I am in the process of converting inline SQL to Stored Procedure. The following is the inline Script.
cmdText += "insert into scopeofworktoapptresultsoverride(scopeofworkid, overwrittentext, createdbyid, datecreated, alptorprodid, isaccomplishlist, isproducttype, ismaterial, apptresultid) "
cmdText += "values (" & iNewOverrideId & ", '" & sText & "', " & iEmployeeId & ", getdate(), " & iTiedToId & ", "
If sTiedTo = "material" Then
cmdText += "0, 0, 1 "
ElseIf sTiedTo = "producttype" Then
cmdText += "0, 1, 0 "
Else
cmdText += "1, 0, 0 "
End If
cmdText += ", " & iResult & " )"
I have already converted this inline SQL like below. Is anyother way to implement this in a single insert statement with case...when.... or some best way.....
IF @sTiedTo = 'material'
BEGIN
INSERT INTO scopeofworktoapptresultsoverride (
scopeofworkid
,overwrittentext
,createdbyid
,datecreated
,alptorprodid
,isaccomplishlist
,isproducttype
,ismaterial
,apptresultid
)
VALUES (
@iNewOverrideId
,@sText
,@iEmployeeId
,getdate()
,@iTiedToId
,0
,0
,1
,@iResult
)
END
ELSE IF @sTiedTo = 'producttype'
BEGIN
INSERT INTO scopeofworktoapptresultsoverride (
scopeofworkid
,overwrittentext
,createdbyid
,datecreated
,alptorprodid
,isaccomplishlist
,isproducttype
,ismaterial
,apptresultid
)
VALUES (
@iNewOverrideId
,@sText
,@iEmployeeId
,getdate()
,@iTiedToId
,0
,1
,0
,@iResult
)
END
ELSE
BEGIN
INSERT INTO scopeofworktoapptresultsoverride (
scopeofworkid
,overwrittentext
,createdbyid
,datecreated
,alptorprodid
,isaccomplishlist
,isproducttype
,ismaterial
,apptresultid
)
VALUES (
@iNewOverrideId
,@sText
,@iEmployeeId
,getdate()
,@iTiedToId
,1
,0
,0
,@iResult
)
END