Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 need help

Author  Topic 

GaneshRamanan
Starting Member

40 Posts

Posted - 2011-01-05 : 02:42:58
pls help me..

create table #schedule (id int identity(1,1),fromtime datetime,appointmenttime datetime,totime datetime,status varchar(5))

insert into #schedule (fromtime,appointmenttime,totime,status)
select starttime,appointmenttime,endtime,'f' from opm.PanelDoctorDetail

create table #scheduledetail(tokenno int identity(1,1), starttime datetime,appointment datetime,endtime datetime)

declare
@maxx int
select @maxx=MAX(id) from #schedule

insert into #scheduledetail(tokenno,starttime,appointment,endtime)
select @maxx+@tokenno,getdate(),getdate(),getdate() from #schedule

i need to insert the values in the #scheduledetail table but the tokenno will be incremented from max(id) from #schedule

Thanks,
Ganesh

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-01-05 : 02:50:37
create table #scheduledetail(tokenno int, starttime datetime,appointment datetime,endtime datetime)

now it should work.
But maybe you really want
insert into #schedule (fromtime,appointmenttime,totime,status)
select starttime,appointmenttime,endtime,'f' from opm.PanelDoctorDetail

select @maxx = scope_identity()

insert into #scheduledetail(tokenno,starttime,appointment,endtime)
select @maxx,getdate(),getdate(),getdate() from #schedule


Not sure what you are trying to acheive with the @maxx+@tokenno.
If it's just a sequence number on detail rows then it should be a separate column.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

GaneshRamanan
Starting Member

40 Posts

Posted - 2011-01-05 : 03:17:12
Hi,

I need to insert the values in #scheduledetail but the tokenno will be the max(id) from #schedule

if suppose

In #schedule table max(id)=68

i need the tokenno will starts from 69 in scheduledetail table

Thanks in advance.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-01-05 : 03:19:09
So you insert schedule 68
detail 69, 70, 71
next schedule = 69
detail = 70, 71, ...
duplicate ids in the detail table.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -