two select statements in one insert statement

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 38
Reputation: q8_dreamy is an unknown quantity at this point 
Solved Threads: 0
q8_dreamy q8_dreamy is offline Offline
Light Poster

two select statements in one insert statement

 
0
  #1
Aug 10th, 2009
hiiii how can I use 2 different select statement to insert 2 different values in same insert statement ????
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: two select statements in one insert statement

 
0
  #2
Aug 10th, 2009
  1. IF OBJECT_ID('TestTable', 'U') IS NOT NULL DROP TABLE TestTable
  2. CREATE TABLE TestTable
  3. (
  4. Col1 VARCHAR(30),
  5. Col2 VARCHAR(30)
  6. )
  7. INSERT INTO TestTable (Col1, Col2) VALUES ('a', 'b')
  8. GO
  9.  
  10. IF OBJECT_ID('tempdb..#Temp', 'U') IS NOT NULL DROP TABLE #Temp
  11. CREATE TABLE #Temp
  12. (
  13. Col1 VARCHAR(30),
  14. Col2 VARCHAR(30)
  15. )
  16.  
  17. GO
  18.  
  19. --Now we have our test data setup
  20.  
  21. INSERT INTO #Temp (Col1, Col2)
  22. SELECT
  23. (SELECT Top 1 Col1 FROM TestTable) As Col1,
  24. (SELECT Top 1 Col2 FROM TestTable) As Col2
  25.  
  26. SELECT *
  27. FROM #Temp
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 38
Reputation: q8_dreamy is an unknown quantity at this point 
Solved Threads: 0
q8_dreamy q8_dreamy is offline Offline
Light Poster

Re: two select statements in one insert statement

 
0
  #3
Aug 10th, 2009
I got unspecified error
this is my code:

("insert into Results (cnt, a_q1) select(select count (*) from Answers) as cnt, (select count(*) from Answers where answer_q1='ضعيف')as a_q1")
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: two select statements in one insert statement

 
0
  #4
Aug 10th, 2009
This is the same question you asked in:
http://www.daniweb.com/forums/thread210160.html

I will respond on the original thread.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 38
Reputation: q8_dreamy is an unknown quantity at this point 
Solved Threads: 0
q8_dreamy q8_dreamy is offline Offline
Light Poster

Re: two select statements in one insert statement

 
0
  #5
Aug 10th, 2009
solved I put from at the end
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,187
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 571
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: two select statements in one insert statement

 
0
  #6
Aug 10th, 2009
Good deal

Please mark these threads as solved as you have found an answer to your question and good luck!
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC