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.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-09-16 : 08:39:01
|
awfdml writes "Need a little help ...i am trying to create a temp table with a result set from a record query that yields, a two column multiple row resultset.I would like to obtain the second column from the first result set and make that the first row in the first column of my temp table, then the first column from the second result set and make that the first row in the second column of my temp table, etc.I.Eresultset:color l numbergreen l 0blue l 1red l 2black l 3 TO #temptable A l B0 l blue1 l red2 l blackI have tried to do this but yielded :A l B0 l NULL1 l NULL2 l NULLNULL l blueNULL l redNULL l blackNot exactly the results I need I would GREATLY appreciate any help!!! Here is the exact syntax of what i am trying to do:I have this in a stored procedure that passes a datetime and room:create table #table (starttime int, endtime int)insert #table (starttime)SELECT end_timeFROM timesWHERE type= 'R'and room = @roomand start_date= @sdateand end_time <> 1440ORDER BY start_date, end_date, start_time, end_timeinsert #table (endtime)SELECT start_timeFROM timesWHERE type = 'R'and room = @roomand start_date = @sdateand start_time <> 0ORDER BY start_date, end_date, start_time, end_timeselect * from #tabledrop table #tableThe problem may stem from the fact that I am doing two seperate inserts into the temp table but I am not sure how to do one insert with 2 different select statements.I would GREATLY appreciate it if someone can help me! Ive been looking at this for 3 days :( THANKS!" |
|
gpl
Posting Yak Master
195 Posts |
Posted - 2004-09-16 : 09:25:54
|
What does your table look like ?Im thinking you either want to UNION ALL your 2 resultsets, or - update the existing values with your 2nd setOr -- we could go for broke and do it all in 1 go, but Id need to see the table structure and a little explanation of what your business rules are (eg end_time <> 1440, what does that mean ?)Graham |
|
|
drymchaser
Aged Yak Warrior
552 Posts |
Posted - 2004-09-16 : 09:54:06
|
Not sure but you could try this:SELECT a.end_time, b.start_timeFROM times a JOIN times b ON a.type = b.type AND a.room = b.room AND b.start_time <> 0WHERE a.type= 'R'AND a.room = @roomAND a.start_date= @sdateAND a.end_time <> 1440 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2004-09-16 : 10:18:12
|
Yes, I like the concept of JOINS drymchaser,maybe awfdml could look into that ;)...can be found in the SQL manual....rockmoose/* Chaos is the nature of things...Order is a lesser state of chaos */ |
|
|
|
|
|
|
|