Click here to Skip to main content
15,888,031 members
Home / Discussions / Database
   

Database

 
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 
QuestionAlter statement - Pin
vkEE13-Nov-13 4:46
vkEE13-Nov-13 4:46 
AnswerRe: Alter statement - Pin
Richard Deeming13-Nov-13 5:10
mveRichard Deeming13-Nov-13 5:10 
AnswerRe: Alter statement - Pin
RedDk15-Nov-13 11:55
RedDk15-Nov-13 11:55 
QuestionOLAP database missing... Pin
SalCon12-Nov-13 22:46
SalCon12-Nov-13 22:46 
SuggestionRe: OLAP database missing... Pin
Richard MacCutchan13-Nov-13 0:37
mveRichard MacCutchan13-Nov-13 0:37 
AnswerRe: OLAP database missing... Pin
GuyThiebaut13-Nov-13 2:57
professionalGuyThiebaut13-Nov-13 2:57 
QuestionMariaDB and c# Pin
Septimus Hedgehog12-Nov-13 3:59
Septimus Hedgehog12-Nov-13 3:59 
AnswerRe: MariaDB and c# Pin
Simon_Whale13-Nov-13 3:40
Simon_Whale13-Nov-13 3:40 
GeneralRe: MariaDB and c# Pin
Septimus Hedgehog13-Nov-13 7:29
Septimus Hedgehog13-Nov-13 7:29 
AnswerTested successfully. Pin
Septimus Hedgehog14-Nov-13 1:12
Septimus Hedgehog14-Nov-13 1:12 
QuestionConcat NULL yields NULL inside a Function Pin
Fabricio Dos Santos Antunes12-Nov-13 0:36
Fabricio Dos Santos Antunes12-Nov-13 0:36 
AnswerRe: Concat NULL yields NULL inside a Function Pin
Simon_Whale12-Nov-13 1:01
Simon_Whale12-Nov-13 1:01 
AnswerRe: Concat NULL yields NULL inside a Function Pin
Mycroft Holmes12-Nov-13 1:57
professionalMycroft Holmes12-Nov-13 1:57 
SuggestionRe: Concat NULL yields NULL inside a Function Pin
Richard Deeming12-Nov-13 3:08
mveRichard Deeming12-Nov-13 3:08 

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.