i have the Following sql code:
print @c_query----- output: SELECT METER_REGISTRATION_ID AS ID,METER_REGISTRATION_ID AS NAME FROM [dbo].[D0150_NHH_METER_TECH_DET_T] WHERE REG_ID=
SET @TEMP_ITEM_VALUE = N'SELECT TOP 1 ID FROM (' + @c_query + '' + Convert(Varchar(max),@REGID) + ') AS ID'
print @TEMP_ITEM_VALUE---- output: SELECT TOP 1 ID FROM (SELECT METER_REGISTRATION_ID AS ID,METER_REGISTRATION_ID AS NAME FROM [dbo].[D0150_NHH_METER_TECH_DET_T] WHERE REG_ID=9217) AS ID
EXEC SP_EXECUTESQL @TEMP_ITEM_VALUE, N'@RESULT NVARCHAR(200) OUT', @RESULT OUT
print @RESULT----- Expected Result: s but getting null
IF(@RESULT IS NULL)
BEGIN
print 'null'
SET @ITEM_VALUE = ''
END
ELSE
BEGIN
SET @ITEM_VALUE = @RESULT
END
what i am doing wrong here? i am getting null.
Is my format is right?