To get time in sql Select CONVERT(varchar(50),getdate(),108) getTime
Posts
Showing posts from August, 2012
- Get link
- X
- Other Apps
To Display Current Week data in sql :- CREATE FUNCTION dbo.udf_DisplayCurrentWeekDateDays ( @today SMALLDATETIME ) RETURNS @WeekDateDay TABLE ( Sunday SMALLDATETIME , Monday SMALLDATETIME , Tuesday SMALLDATETIME , Wednesday SMALLDATETIME , Thursday SMALLDATETIME , Friday SMALLDATETIME , Saturday SMALLDATETIME ) AS BEGIN DECLARE @day INT SET @today = CAST ( CONVERT ( VARCHAR ( 10 ), @today , 101 ) AS SMALLDATETIME ) SET @day = DATEPART ( dw , @today ) INSERT INTO @WeekDateDay ( Sunday , Monday , Tuesday , Wednesday , Thursday , Friday , Saturday ) SELECT DATEADD ( dd , 1 - @day , @today ) Sunday , DATEADD ( dd , 2 - @day , @today ) Monday , DATEADD ( dd , 3 - @day , @today ) Tuesday , DATEADD ( dd , 4 - @day , @today ) Wednesday , DATEADD ( dd , 5 - @day , @today ) Thursday , DATEADD ( dd , 6 - @day , @today ) Friday , DATEADD ( dd , 7 - @day , @today ) Saturday RETURN END GO for more reference :- http://blog.sqlauthority.com/2007/06/08/sql-server-...
- Get link
- X
- Other Apps
How to convert table data from horizontal into vertical in sql :- declare @t table (id int, nm varchar(10), typ varchar(10), color varchar(10), qty int, txt varchar(10)) insert @t select 1, 'name1', 'type1', 'color1', 10, 'note1' union all select 2, 'name2', 'type2', 'color2', 20, 'note2' select up.id ,up.col as sourcecolumn ,up.val as [value] from ( select id, nm,typ,color,convert(varchar(10), qty) qty,txt from @t --YOUR TABLE ) d unpivot (val for col in ([nm], [typ], [color],[qty],[txt])) up
- Get link
- X
- Other Apps
Varieties of dates available in sql server :- Declare @Date datetime SET @Date = '1/1/2011' WHILE @Date < '1/1/2012' BEGIN SELECT CONVERT(VARCHAR(8), @Date, 112) date1, @Date fulldate, YEAR(@Date) years, DATEPART(qq, @Date) quater, DATEPART(ww, @Date) yearweeks, DATENAME(dw, @Date) dayname, DATEPART(dd, @Date) dateno, DATENAME(mm, @Date) monthnam, DATEPART(dy,@Date) daycnt, DATENAME(mm, @Date) + ' ' + CAST(DATEPART(dd, @Date) AS CHAR(2)) + ',' + CAST(DATEPART(yy, @Date) AS CHAR(4)) [mm dd,yyyy], CONVERT(VARCHAR(10), @Date, 101) normaldate, DATEPART(dw, @Date) , DATEPART(mm, @Date) dateno SET @Date = DATEADD(dd, 1, @Date) END