p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   SQL Server 2005 (http://p2p.wrox.com/forumdisplay.php?f=220)
-   -   Check value while insert in stored procedure (http://p2p.wrox.com/showthread.php?t=70004)

Andraw August 11th, 2008 10:03 PM

Check value while insert in stored procedure

I create stored procedure inside it I will read a text file and insert each row into a table.

For example the table is as the following:
ID (primary key), lName, fName, age, address.............,

I create a cursor then fetch data to @ID, @lName, @fName, @age, @adress, then:

Insert into xxxTable(ID, lName, fName, age,address) Values (@ID, @lName, @fName, @age, @address)

But I want to check data before insert, for example, if @address = '', I wish to insert NULL, otherwise, insert @address, what is the easy way to do it? because I have 100 lines to insert, and each line has 65 fields, so I want to put the data checking inside the insert statement, is it possible?

in case there is ' char in address, is there some function like REPLACE in sp so I can replace ' to ''.



Jeff Moden August 11th, 2008 11:15 PM

Don't use a cursor... just do an INSERT/SELECT. And, if address is blank, you can use NULLIF.


--Jeff Moden

Andraw August 12th, 2008 09:08 AM


All times are GMT -4. The time now is 04:22 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.