I have a database table that was imported from a csv file which had NULL in it, so that when it was imported instead of fields being NULL they contain the string value 'NULL'.
The CSV file is to big to open in a text editor to edit out all of the NULL so I am trying to create a SQL query to update each column of the table.
So far I have this
Alter PROCEDURE [dbo].[sp_fixnulls]
@column nvarchar(100)
AS
BEGIN
SET NOCOUNT ON;
UPDATE my_table
SET @column=''
WHERE @column = 'NULL'
END
---------------
sp_fixnulls (SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='my_table')
but this is not working. I get the error message
Msg 201, Level 16, State 4, Procedure sp_fixnulls, Line 0
Procedure or function ‘sp_fixnulls’ expects parameter ‘@column’, which was not supplied.
@column is a variable. It cannot dynamically swap out its contents into SQL. You need to use TSQL to accomplish this, whereby you generate the SQL into a string then execute it. Such as:
A small note that my code sets the column to empty string, which is NOT the same as NULL. I went with your existing example. If you want NULL, then