Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 11th, 2008, 10:03 PM
Friend of Wrox
 
Join Date: Jan 2005
Location: Houston, TX, USA.
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

















Reply With Quote
  #2 (permalink)  
Old August 11th, 2008, 11:15 PM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
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
Reply With Quote
  #3 (permalink)  
Old August 12th, 2008, 09:08 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Houston, TX, USA.
Posts: 108
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:58 AM.


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