Gen

select CAST(CONVERT(VARCHAR(11), GETDATE(), 113) AS DATETIME)
select DATENAME(dw, GETDATE())
select DATENAME(mm, GETDATE())
IF DATENAME(dw, GETDATE()) IN (‘Saturday’,’Sunday’)

DATEADD(mi, GETDATE(), Locked)
select DATEPART(dd, GETDATE())
(CASE WHEN CHARINDEX(‘a’, AP.SendMethod)

select CAST(‘1 ‘ + DATENAME(MONTH, GETDATE()) + ‘ ‘ + DATENAME(YEAR, GETDATE()) AS DATETIME)FDMonth
select DATEADD(dd,DATEDIFF(dd, 0, CAST(‘1 ‘ + DATENAME(MONTH, GETDATE()) + ‘ ‘ + DATENAME(YEAR, GETDATE()) AS DATETIME)),1) FDMonth

select DATEADD(dd, DATEDIFF(dd, 0, Getdate()), 0)

, DATEADD(ss, -1, DATEADD(dd, DATEDIFF(dd, 0, Getdate()), 1))

IF OBJECT_ID(‘tempdb..#Results’) IS NOT NULL DROP TABLE #Results

/////////////////////////

SELECT DATENAME(dw, GETDATE())
DECLARE @a DECIMAL
DECLARE @s DECIMAL
DECLARE @d DECIMAL(18,12)
set @a=22
set @s= 7
set @d= @a/@s
SELECT round (@d,5)
SELECT round (@d,4)
select cast( @d as decimal(16,2))

////////////////////////

DECLARE @MyDateTime DATETIME
/* Add 5 seconds to current time so
system waits for 5 seconds*/
Select DATEADD(s,50000,GETDATE())

select ISDATE(‘1/23/95’)

select CAST(FLOOR(CAST(GETDATE() AS DECIMAL(12, 5))) AS DATETIME)

SELECT CHARINDEX(‘lo w0′,’Hello World’);

SELECT CHARINDEX(‘o’,’Hello World’,6);

select REPLACE(‘1s1’, ‘s’,”)

/////////////////////////////

select DATEADD(dd, DATEDIFF(dd, 0, Getdate()), 0)

, DATEADD(ss, -1, DATEADD(dd, DATEDIFF(dd, 0, Getdate()), 1))

////////////////////////////////////////

DECLARE @ID INT
DECLARE test CURSOR FAST_FORWARD read_only FOR
SELECT TOP 1000 [aid]

FROM [tst].[dbo].[A]

OPEN test
FETCH NEXT FROM test INTO @ID

WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @ID
FETCH NEXT FROM test INTO @ID
END
CLOSE test
DEALLOCATE test
//////////////////////////////////////////////////////////////////////

Declare @total int
Declare @tot varchar(max)
set @total =0
SELECT @total = @total+ [aid]
FROM [tst].[dbo].[A]

SELECT @tot =ISNULL( @tot,”)+ CONVERT(varchar(10), [aid])+’,’

FROM [tst].[dbo].[A]

select @tot

select SUBSTRING(@tot, 1 , len(@tot)-1)
select @total

/////////////////////////////////////////////////////////////////////

declare @hid int, @cnt int
create table #test( id int identity, ida int, naam varchar(100))
insert into #test
SELECT TOP 1000 [aid]
,[name]
FROM [tst].[dbo].[A] with(nolock)
set @cnt =0
set @hid =@@IDENTITY
while @cnt < @hid
begin
select * from #test where id= @cnt+1
set @cnt +=1
end
drop table #test

///////////////////////////////////////////////////////////////////

Declare @total int
Declare @tot varchar(max)
set @total =0
SELECT @total = @total+ [aid]
FROM [tst].[dbo].[A]

SELECT @tot =ISNULL( @tot,”)+ CONVERT(varchar(10), [aid])+’,’

FROM [tst].[dbo].[A]

select @tot

select SUBSTRING(@tot, 1 , len(@tot)-1)
select @total

////////////////////////////////////////////

SELECT DATENAME(dw, GETDATE())
DECLARE @a DECIMAL
DECLARE @s DECIMAL
DECLARE @d DECIMAL(18,12)
set @a=22
set @s= 7
set @d= @a/@s
SELECT round (@d,5)
SELECT round (@d,4)
select cast( @d as decimal(16,2))

//////////////////////////////////////////////////////////////////////////////////

use tempdb
if object_id(‘tempdb..#staff’) is null
begin

create table #staff
(id int identity, ename varchar(10),mname varchar(10))
end

insert into #staff values(‘A’, null)

insert into #staff values(‘B’, ‘A’)
insert into #staff values(‘D’, ‘B’)
insert into #staff values(‘E’, ‘B’)
insert into #staff values(‘C’, ‘A’)
insert into #staff values(‘F’, ‘C’)
insert into #staff values(‘G’, ‘C’)
insert into #staff values(‘H’, ‘G’)
insert into #staff values(‘J’, ‘G’)

select * from #staff

;with stmgr as
(
select id, ename, mname, 0 as Elevel from #staff where mname is null

union all

select emp.id, emp.ename , emp.mname ,Elevel+1 from #staff emp
inner join stmgr mgr
on emp.mname = mgr.ename

)

select * from stmgr
order by mname
if object_id(‘tempdb..#staff’) is not null
drop table #staff

//////////////////////////////////////////////////////////////////////////

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: