Showing posts with label sql 2008. Show all posts
Showing posts with label sql 2008. Show all posts

Thursday, March 6, 2014

Get Date/Time from datetime datatype SQL SERVER

To get DatePart of DateTime type

SELECT CONVERT(DATE,GETDATE()) AS DateOnly

To get Time part in

SELECT CONVERT(TIME,GETDATE()) AS HourMinuteSeconds;
SELECT convert(varchar(8),GETDATE(), 108)

Monday, April 2, 2012

SQL pagination help

This code is just for my reference.

declare @t table                    
        (                    
          idx int identity,                    
          intColumnID int, primary key clustered( idx)        
        )


declare @rowcount int,                    
        @total INT,                    
        @return_value int  
       
   select @rowcount = (@intPageId + 5) * @intpageSize
   select @intPageId = @intPageId - 1
 
 if @intPageId < 0
select @intPageId = 1;

insert into @t

select   ColumnId from [dbo].tablename where
-- Condition  add all conditions here to make sure that count will b correct

 select  @total = @@rowcount
        set rowcount @intPageSize
    -- Insert statements for procedure here

SELECT * from @t t
join tablename on tablename.columnId=t.intColumnID
WHERE   t.idx >= @intPageId * @intPageSize + 1

order by t.idx    asc
return @total