vigneshlagoons (10/17/2013)
Hi,I am new to SQL and where should I declare that. I have no idea. If possible can you correct my query.
DECLARE @CCSG bit
DECLARE @User ?? -- (?? = whatever data type this should be)
SET @User = ?? -- (?? whatever value that should be used, if a string surrounded by single quotes)
SET @CCSG = CASE WHEN EXISTS(SELECT 1
FROM USER_PRFL up
INNER JOIN BSP_LOB_Grp_Lookup bl
ON bl.BSP_LOB_GRP = up.User_Group
INNER JOIN IMPACTED_LOB il
ON il.BSP_LOB_CD = bl.BSP_LOB_CD
WHERE BSP_LOB_GRP = 'CCSG Group'
AND up.UserName=@User
)
THEN 1 ELSE 0 END
SELECT *
FROM USER_PRFL up
INNER JOIN BSP_LOB_Grp_Lookup bl
ON bl.BSP_LOB_GRP = up.User_Group
INNER JOIN IMPACTED_LOB il
ON il.BSP_LOB_CD = bl.BSP_LOB_CD
WHERE (up.UserName=@User AND @CCSG = 0)
OR (BSP_LOB_GRP IN ('LOB Group','Site Group','Sales Group','CCSG Group') AND @CCSG = 1)