Click here to Skip to main content
15,898,984 members
Home / Discussions / Database
   

Database

 
Questionfind total money of parent node of tree according to a particular pattern Pin
jitendra raj20-Nov-13 5:54
jitendra raj20-Nov-13 5:54 
AnswerRe: find total money of parent node of tree according to a particular pattern Pin
Mycroft Holmes20-Nov-13 19:25
professionalMycroft Holmes20-Nov-13 19:25 
GeneralRe: find total money of parent node of tree according to a particular pattern Pin
jitendra raj20-Nov-13 22:46
jitendra raj20-Nov-13 22:46 
GeneralRe: find total money of parent node of tree according to a particular pattern Pin
Mycroft Holmes21-Nov-13 1:35
professionalMycroft Holmes21-Nov-13 1:35 
AnswerRe: find total money of parent node of tree according to a particular pattern Pin
Jörgen Andersson21-Nov-13 1:37
professionalJörgen Andersson21-Nov-13 1:37 
GeneralRe: find total money of parent node of tree according to a particular pattern Pin
jschell21-Nov-13 8:30
jschell21-Nov-13 8:30 
QuestionDynamic Filter Stored Procedure Pin
Commish1319-Nov-13 6:38
professionalCommish1319-Nov-13 6:38 
AnswerRe: Dynamic Filter Stored Procedure Pin
Mycroft Holmes19-Nov-13 12:02
professionalMycroft Holmes19-Nov-13 12:02 
Questionhow to write MAX query Pin
spanner2118-Nov-13 20:15
spanner2118-Nov-13 20:15 
AnswerRe: how to write MAX query Pin
Wayne Gaylard18-Nov-13 20:39
professionalWayne Gaylard18-Nov-13 20:39 
GeneralRe: how to write MAX query Pin
spanner2118-Nov-13 21:11
spanner2118-Nov-13 21:11 
GeneralRe: how to write MAX query Pin
Wayne Gaylard18-Nov-13 21:17
professionalWayne Gaylard18-Nov-13 21:17 
AnswerRe: how to write MAX query Pin
Mycroft Holmes18-Nov-13 21:11
professionalMycroft Holmes18-Nov-13 21:11 
AnswerRe: how to write MAX query Pin
Peter Leow18-Nov-13 23:39
professionalPeter Leow18-Nov-13 23:39 
Questionhow can optimize a query in sql server Pin
mhd.sbt17-Nov-13 4:15
mhd.sbt17-Nov-13 4:15 
AnswerRe: how can optimize a query in sql server Pin
Maciej Los17-Nov-13 5:44
mveMaciej Los17-Nov-13 5:44 
GeneralRe: how can optimize a query in sql server Pin
PIEBALDconsult18-Nov-13 15:42
mvePIEBALDconsult18-Nov-13 15:42 
AnswerRe: how can optimize a query in sql server Pin
Jörgen Andersson18-Nov-13 3:00
professionalJörgen Andersson18-Nov-13 3:00 
QuestionSRSS 2008 RepeatOnNewPage not really work on the “2nd last” page Pin
F.E.L.I.X.15-Nov-13 0:44
F.E.L.I.X.15-Nov-13 0:44 
GeneralMessage Closed Pin
14-Nov-13 15:34
professionalMember 1040275014-Nov-13 15:34 
GeneralRe: Hadoop + esProc Help You Replace IOE Pin
Eddy Vluggen14-Nov-13 22:29
professionalEddy Vluggen14-Nov-13 22:29 
Questionstoredprocedures Pin
Member 1039766114-Nov-13 4:07
Member 1039766114-Nov-13 4:07 
Greetings,

below command works fine. but everytime when i want to update another quess and buildingpoint .i need to change quess_2 ,q2buildingpoint.So i write all 12 ques and 12 builgpoints .So my question is i want output like this with stored procedures.Can anyone please suggest or modify my stored procedure.

output

exec 2,5,5 ---this out put effects in survey table (cid,ques_5 ,q5buildpoint)

exec 3,5,5 ---this out put effects in survey table (cid,ques_5 ,q5buildpoint)


UPDATE survey SET
ques_1 = (select response from surveyanswers t2 where id=@response),q1buildpoint=(select response from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID
End


can i write procedure like this .it thows errors .can anyone please suggset something on this below procedure.How can i add if else conditions


ALTER PROCEDURE [dbo].[UpdateSurvey]
-- Add the parameters for the stored procedure here
@ID int,@response nvarchar(50),@buildingpoint nvarchar(50)
AS
BEGIN

if(@ID=1) then
Begin
UPDATE survey SET
ques_1 = (select response from surveyanswers t2 where id=@response),q1buildpoint=(select response from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID
End

Else If(@ID=2) then

Begin
UPDATE survey SET
ques_2a = (select response from surveyanswers t2 where id=@response),q2abuildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID
End

Else If(@ID=3) then

Begin
UPDATE survey SET
ques_2b = (select response from surveyanswers t2 where id=@response),q2bbuildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID

Else If(@ID=4) then

Begin

UPDATE survey SET
ques_2c = (select response from surveyanswers t2 where id=@response),q2cbuildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID


Else If(@ID=3) then

Begin


UPDATE survey SET
ques_3 = (select response from surveyanswers t2 where id=@response),q3buildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID


Else If(@ID=3)then

Begin
UPDATE survey SET
ques_4 = (select response from surveyanswers t2 where id=@response),q4buildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID


Else If(@ID=3) then

Begin
UPDATE survey SET
ques_5 = (select response from surveyanswers t2 where id=@response),q5buildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID


Else If(@ID=3) then

Begin
UPDATE survey SET
ques_6 = (select response from surveyanswers t2 where id=@response),q6buildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID

Else If(@ID=3) then

Begin
UPDATE survey SET
ques_7 = (select response from surveyanswers t2 where id=@response),q7buildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID

Else If(@ID=3)then

Begin
UPDATE survey SET
ques_8 = (select response from surveyanswers t2 where id=@response),q8buildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID


Else If(@ID=3)then

Begin
UPDATE survey SET
ques_9 = (select response from surveyanswers t2 where id=@response),q9buildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID


Else If(@ID=3)then

Begin

UPDATE survey SET
ques_10 = (select response from surveyanswers t2 where id=@response),q10buildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID

Else If(@ID=3)then

Begin
UPDATE survey SET
ques_11 = (select response from surveyanswers t2 where id=@response),q11buildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID

End
Else If(@ID=3) then

Begin
UPDATE survey SET
ques_12= (select response from surveyanswers t2 where id=@response),q12buildpoint=(select buildingpoint from surveyanswers t2 where id=@buildingpoint)
from survey c
inner join surveyanswers s
on s.id = c.cid
where c.cid = @ID
End
End
End
------
--exec UpdateSurvey 10,19,19

--select * from survey
--select * from surveyanswers

Errors

Msg 156, Level 15, State 1, Procedure UpdateSurvey, Line 58
Incorrect syntax near the keyword 'then'.
Msg 156, Level 15, State 1, Procedure UpdateSurvey, Line 71
Incorrect syntax near the keyword 'Else'.
Msg 156, Level 15, State 1, Procedure UpdateSurvey, Line 71
Incorrect syntax near the keyword 'then'.
Msg 156, Level 15, State 1, Procedure UpdateSurvey, Line 82
Incorrect syntax near the keyword 'Else'.
Msg 156, Level 15, State 1, Procedure UpdateSurvey, Line 82
Incorrect syntax near the keyword 'then'.
Msg 156, Level 15, State 1, Procedure UpdateSurvey, Line 93
Incorrect syntax near the keyword 'Else'.
Msg 156, Level 15, State 1, Procedure UpdateSurvey, Line 93
Incorrect syntax near the keyword 'then'.
AnswerRe: storedprocedures Pin
Eddy Vluggen14-Nov-13 6:52
professionalEddy Vluggen14-Nov-13 6:52 
GeneralRe: storedprocedures Pin
Member 1039766114-Nov-13 7:31
Member 1039766114-Nov-13 7:31 
GeneralRe: storedprocedures Pin
Eddy Vluggen16-Nov-13 1:26
professionalEddy Vluggen16-Nov-13 1:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.