I have these two queries that work separately but I am not sure how to combine them so they work together. The idea is if a certain value exists in my select query, I need to run another select query.GOCREATE FUNCTION dbo.BuildString(@Owner VARCHAR(8000))RETURNS VARCHAR(8000)ASBEGIN DECLARE @Output VARCHAR(8000) SELECT @Output = COALESCE(@Output+', ', '') + CONVERT(varchar(100), U.PROMPT) FROM UDF U JOIN UDFValue V ON U.UDFID = V.UDFID WHERE V.OwnerID = @Owner AND V.ItemValue = 'Yes' AND (U.UDFID = 10001 OR U.UDFID = 10002 OR U.UDFID = 10003 OR U.UDFID = 10004 OR U.UDFID = 10005 OR U.UDFID = 10006 OR U.UDFID = 10007 OR U.UDFID = 10008 OR )/* If U.UDFID = 10009 How can I get this to work? */ ORDER BY U.PROMPT RETURN @OutputENDGOUPDATE UserInformation SET Title = dbo.BuildString(444) WHERE UserID = 444 GODROP FUNCTION dbo.BuildStringGO
Here is the other query running separately as I was trying to see if I could get it working by itself with CASE, I've tried dozens of if statements and CASE statements to get it to work in the above, but I can't get it functioning and something always results in an error. Having two queries like this separate would have a lot of overhead right?:DECLARE @Owner VARCHAR(8000) = 444DECLARE @Output VARCHAR(8000)SET @Output = (select UDFID = case WHEN U.UDFID = 10009 AND V.ItemValue = 'Yes' THEN (SELECT ItemValue FROM UDFvalue WHERE UDFID = 10010 AND OwnerID = 444) endFROM UDF U JOIN UDFValue V ON U.UDFID = V.UDFIDWHERE V.OwnerID = @OwnerAND V.ItemValue = 'Yes')
Thanks for any help