is it possible to apply is Null and Trim in all columns of table


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

Who is Participating?
Evan CutlerVolunteer Chief Information OfficerCommented:
Just a side note, this sounds awefully like an ETL job.
Have you considered an ETL process to upload your data at regular intervals.  
Some of the new ETL tools are open source (meaning free), and have UI functions
to counterman these  issues.
Please, elaborate a little bit - what are you doing specifically - do yout read resultSet with JDBC - in what suituation are you using these
isNull() and trim() - do you mean java methods or something ion SQL side?

Please, be a little bit more claer on this.
Evan CutlerVolunteer Chief Information OfficerCommented:
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?
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Evan CutlerVolunteer Chief Information OfficerCommented:
sorry, replace 'YourTableName' with the table you are running this on.
kumarjcetAuthor Commented:
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
Evan CutlerVolunteer Chief Information OfficerCommented:
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?
kumarjcetAuthor Commented:
hi arcee123 :...its a batchjob work it will run every 30 min  and pull data from some remote database ...

Evan CutlerVolunteer Chief Information OfficerCommented:'s got spaces, adn who's got nulls?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.