Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 11th, 2008, 10:03 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default Check value while insert in stored procedure

Hi,

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 ''.

Thanks!

Andraw

















 
Old August 11th, 2008, 11:15 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

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

NULLIF(Address,'')

--Jeff Moden
 
Old August 12th, 2008, 09:08 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure Insert Null Value harpua SQL Server ASP 2 March 5th, 2005 10:19 AM
stored procedure dynamic insert harpua Classic ASP Databases 3 January 21st, 2005 12:50 AM
How do I insert stored procedure through C# nishim.attreja VB How-To 1 September 18th, 2004 01:24 AM
Check if stored procedure exists. phil SQL Server 2000 3 February 9th, 2004 10:37 AM
Using an insert stored procedure morpheus VB How-To 3 August 7th, 2003 08:42 AM





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