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 |
|
konark
Yak Posting Veteran
60 Posts |
Posted - 2009-07-09 : 13:32:34
|
| Student_ScoreRollNO Subject Score10 HIST 8020 HIST 9030 HIST 8010 GEO 8020 GEO 9030 GEO 80Student_targetRollNO Subject Target10 HIST 10020 HIST 10030 HIST 10010 GEO 15020 GEO 15030 GEO 150Set @Target='HIST'Set @target = 100Declare @Target as Table(RollNo Varchar(5), Subject Varchar(5), Target int)insert into @target(select rollno,@subject,@target from Student_Score)Insert into Student_targetselect rollno,subject,score from @targetfor inserting Target for 'GEO' , do i need to make another table variables. How can i make use of a conditional statment to insert both HIST and GEO in one GO.Chandragupta Mourya |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
konark
Yak Posting Veteran
60 Posts |
Posted - 2009-07-09 : 14:49:38
|
| I have understood correctly. Looks like you didnt understand the depth of the problemChandragupta Mourya |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2009-07-09 : 14:57:01
|
I'm not sure I understand your actual requirement. Yes, you can add another table variable, but you don;t need to. In fact you could do it without any table variable if you wanted (assuming I think I get what you want):INSERT Student_TargetSELECT RollNO, [Subject], CASE WHEN [Subject] = 'HIST' THEN 100 WHEN [Subject] = 'GEO' THEN 110 ELSE 0 -- Unknown END as [Target]FROM Student_Score-- Might be optionalWHERE [Subject] IN ('HIST', 'GEO') |
 |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2009-07-09 : 15:38:44
|
quote: Originally posted by konark I have understood correctly. Looks like you didnt understand the depth of the problemChandragupta Mourya
very true, this problem is too deep to understandSet @Target='HIST'Set @target = 100Declare @Target as Table(RollNo Varchar(5),Subject Varchar(5),Target int)@target has multiple personality disorder |
 |
|
|
konark
Yak Posting Veteran
60 Posts |
Posted - 2009-07-09 : 17:32:48
|
| Lamprey , sorry i have to use Table variables , as the result set is too large. I needed to know if i can avoid creating another table variable for another subject 'GEO' to insert/update target score for each rollNo. Rohit Kumar. You know little knowledge is dangerous thing. Instead of making out fun ,you could have worked on the solution .Chandragupta Mourya |
 |
|
|
|
|
|
|
|