Sie sind auf Seite 1von 1

declare @t table(id int identity(1,1), names varchar(100)) insert into @t (names) select 'ramesh' union all select 'suresh'

union all select 'nilesh' select 'cus'+right(replicate('0',7)+cast(id as varchar(7)),7) as id,names from @ t declare @t table(id char(10), names varchar(100)) insert into @t select 'cus0000001','ramesh' union all select 'cus0000002','suresh' declare @id int select @id=MAX(substring(id,4,len(id)))*1 from @t insert into @t select 'cus'+RIGHT(REPLICATE('0',7)+cast(@id+1 as varchar(7)),7),'nilesh' select * from @t declare @t table(id int identity(1,1), names varchar(100)) insert into @t (names) select 'ramesh' union all select 'suresh' union all select 'nilesh' select 'cus'+right(replicate('0',7)+cast(id as varchar(7)),7) as id,names from @ t create table #t1 (id int, names varchar(100)) create table #t2 (id int, names varchar(100)) create table #t3 (id int, names varchar(100)) insert into #t1 select 1,'test1' union all select 2,'test2' insert into #t2 select 1,'test1' union all select 3,'test2' insert into #t3 select 1,'test1' union all select 20,'test2' select t1.* from #t1 as t1 inner join #t2 as t2 on t1.id=t2.id inner join #t3 as t3 on t1.id=t3.id select * from #t1 intersect select * from #t2 intersect select * from #t3 declare @num int set @num=872382 select @num as original,right(replicate('0',10)+cast(@num as varchar(15)),10) aS lpad_number, left(cast(@num as varchar(15))+replicate('0',10),10) as rpad_number select cast('19/12/2000' as datetime) select cast('12/19/2000' as datetime) declare @var1 int ,@var2 int select @var1=763, @var2=0 select @var1/case when @var2 =0 then null else @var2 end declare @var1 int ,@var2 int select @var1=763, @var2=0 select @var1/nullif(@var2,0)