Click here to Skip to main content
16,004,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ALTER PROCEDURE [dbo].[S_EDIT_USER]
( @DSA_CODE VARCHAR(10)
,@REQUESTOR_DEPT VARCHAR(40)
,@ACTIVE_STATUS INT
,@MAKER_ID VARCHAR(10)
,@MAKER_IP VARCHAR(20)
,@ERROR_CODE INT OUTPUT
)
AS
BEGIN

DECLARE @CNT INT;
DECLARE @SQL NVARCHAR(MAX);

--DECLARE @REQUESTOR_DEPT VARCHAR(40);
--print(@REQUESTOR_DEPT);
SELECT @CNT = COUNT(*) FROM TMAS_UAM_USER_TMP WHERE DSA_CODE = @DSA_CODE;

IF @CNT > 0
SET @ERROR_CODE = 1;
ELSE
SET @ERROR_CODE = 0;

if @REQUESTOR_DEPT = 'N'
SET @REQUESTOR_DEPT = '';
ELSE
SET @REQUESTOR_DEPT = @REQUESTOR_DEPT ;
print @REQUESTOR_DEPT;

IF @ERROR_CODE = 0

set @SQL = 'INSERT INTO TMAS_UAM_USER_TMP (
DSA_CODE
,DSA_NAME
,DSA_CITY
,DSA_PRODUCT
,DSA_PHNO
,DSA_MOBNO
,DSA_RQSTR
,DSA_RQSTR_DEPT
,GROUP_ID
,ACTIVE_STATUS
,REQ_TYPE
,LAST_LOGED_IN
,CREATED_ID
,CREATED_IP
,CREATED_DATE
,MAKER_ID
,MAKER_IP
,MAKER_DATE
) SELECT DSA_COD
,DSA_NAM
,DSA_CTY
,PRODUCT
,DSA_PHO
,DSA_MOB
,REQUESTOR
,'+@REQUESTOR_DEPT+'
,GROUP_ID
,@ACTIVE_STATUS
,1
,LAST_LOG_DAT
,CREATED_ID
,CREATED_IP
,CREATED_DATE
,'+@MAKER_ID+'
,'+@MAKER_IP+'
,GETDATE()
FROM DSA_MST WHERE DSA_COD = '+@DSA_CODE+' and ';

if @REQUESTOR_DEPT = 'N'
begin
set @SQL = @SQL + 'REQUESTOR_DEPT is null';
print('If Query'+@SQL);
end
else
begin
set @SQL = @SQL + 'REQUESTOR_DEPT = ''' + @REQUESTOR_DEPT + '''';
print('Else Query'+@SQL);
end

--EXEC sp_executesql @SQL, N'@REQUESTOR_DEPT varchar(100) output', @REQUESTOR_DEPT output
--EXECUTE sp_executesql @SQL;
execute (@SQL);
RETURN @ERROR_CODE;
END
Posted

Using a proc to string mash SQL and run it, is retarded. It's a waste of time, you may as well do it in code ( but, don't. )

@ACTIVE_STATUS is inside a string. As such, you're passing this text, NOT the value that was passed in. You need to do the same thing you did for the other variables, ' + @ACTIVE_STATUS + '....

Having said that, while your code is idiotic. the proc is valid and does not give an error when I copy, paste, and create it.

You need to tell us what line has the error, and perhaps even try to simplify this down to a basic example with the minimal code that gives the error.
 
Share this answer
 
i think you are getting error because of the highlighted code given below. Append it to the variable like you are doing for @REQUESTOR_DEPT variable -

SELECT DSA_COD
,DSA_NAM
,DSA_CTY
,PRODUCT
,DSA_PHO
,DSA_MOB
,REQUESTOR
,'+@REQUESTOR_DEPT+'
,GROUP_ID
,@ACTIVE_STATUS
,1
,LAST_LOG_DAT
,CREATED_ID
,CREATED_IP
,CREATED_DATE
,'+@MAKER_ID+'
,'+@MAKER_IP+'
,GETDATE()
FROM DSA_MST WHERE DSA_COD = '+@DSA_CODE+' and ';
 
Share this answer
 
Comments
Member 10484803 24-Dec-13 1:03am    
Already tried this..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900