kumarjcet
asked on
is it possible to apply is Null and Trim in all columns of table
hi,
i have table with 150 columns .i need to apply isnull and trim in all columns .is there any common function available to apply table level
i have table with 150 columns .i need to apply isnull and trim in all columns .is there any common function available to apply table level
Hi...
For the TRIM function:
Run this script:
DECLARE @SQL VARCHAR(MAX) DECLARE @TableName NVARCHAR(128) SET @TableName = 'YourTableName' SELECT @SQL = COALESCE(@SQL + ',[', '[') + COLUMN_NAME + ']=RTRIM([' + COLUMN_NAME + '])' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @TableName AND DATA_TYPE = 'varchar' SET @SQL = 'UPDATE [' + @TableName + '] SET ' + @SQL PRINT @SQL
The output of this script will give you the script to run your trims.
Copy and paste the output back into your workspace and run the output as a sql statement.
All of your columns should be trimmed.
Can I get more info on isnull?
For the TRIM function:
Run this script:
DECLARE @SQL VARCHAR(MAX) DECLARE @TableName NVARCHAR(128) SET @TableName = 'YourTableName' SELECT @SQL = COALESCE(@SQL + ',[', '[') + COLUMN_NAME + ']=RTRIM([' + COLUMN_NAME + '])' FROM INFORMATION_SCHEMA.COLUMNS
The output of this script will give you the script to run your trims.
Copy and paste the output back into your workspace and run the output as a sql statement.
All of your columns should be trimmed.
Can I get more info on isnull?
sorry, replace 'YourTableName' with the table you are running this on.
ASKER
hi i am getting data from some other database its returning for most aof the columns null and and its having some spaces....
i have the same table with my end sql server.i need to check whether that record is already exist or not if exist no need to insert while comparing my table with remote table having some NULL values in column and spaces..while comparing it will show different so it will insert new record ..i need to avoid that
each table having 150 columns
i have the same table with my end sql server.i need to check whether that record is already exist or not if exist no need to insert while comparing my table with remote table having some NULL values in column and spaces..while comparing it will show different so it will insert new record ..i need to avoid that
each table having 150 columns
so you are saying some of the source tables will have spaces, and you have nulls, or the reverse? and it will assume that space != nulls, and try to insert another record as a new one?
Who's got spaces, and who's got nulls?
Who's got spaces, and who's got nulls?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi arcee123 :...its a batchjob work it will run every 30 min and pull data from some remote database ...
ok...so...who's got spaces, adn who's got nulls?
isNull() and trim() - do you mean java methods or something ion SQL side?
Please, be a little bit more claer on this.