Click here to Skip to main content
15,887,421 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
I'm writing a USP to clean a column using REPLACE() method.
The replace command is:
SQL
ALTER PROCEDURE [NetDB].[dbo].[usp_cleanUpProcessForT4]
AS
  BEGIN
  SET NOCOUNT ON
  DECLARE @Command NVARCHAR(MAX)
  SET @command = '
		UPDATE [NetDB].[dbo].[Table4]
		SET [DA_ArticleDetails] = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(DA_ArticleDetails,"||$|| ||$||"," "),"||$||"," ")," ","<>"),"><",""),"<>"," ")'
		BEGIN TRY
		 EXEC(@Command)
		PRINT
		 'Applied rule#1 to 5... Executed Successfully.'
		END TRY
		BEGIN CATCH
			PRINT 'rule#a1 Error'
		SELECT 
		  ERROR_NUMBER() AS ErrorNumber
		  ,ERROR_MESSAGE() AS ErrorMessage;
		END CATCH
END


Here I'm getting the ErrorMessage as
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.


What should I do? Please help.
Posted

1 solution

Hi,

Check this...


SQL
DECLARE @Command NVARCHAR(MAX)

SET @Command = ' UPDATE [NetDB].[dbo].[Table4]
SET [DA_ArticleDetails] = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(DA_ArticleDetails,''||$|| ||$||'','' ''),''||$||'','' ''),'' '',''<>''),''><'',''''),''<>'','' '') '

PRINT(@Command)


Hope this will help you.

Cheers
 
Share this answer
 
v3
Comments
GoneBump 18-Sep-14 3:17am    
I can't believe what I just saw. It was just the double quotes!!! Thanks Magic...
Magic Wonder 18-Sep-14 3:18am    
Your Welcome.

It happens sometime.

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