BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Nulls in SQL Insert statements

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Matthew Pascoe
Guest





PostPosted: Mon Aug 09, 2004 5:28 am    Post subject: Nulls in SQL Insert statements Reply with quote



Hi,

I am writing a stored procedure to insert a record into a table. It is
possible that several of the fields will have either an integer value or be
left as null, depending upon the values of the input parameters.

Is there anyway to cater for this in my SQL insert statement. The only way I
can think to get around it is to have an if statement with different SQL's
depending on which fields are to be left as nulls and which fields are to
receive values.

This stored procedure is to be called from within another stored procedure.

Any help is greatly appreciated.

Thanks
Matthew


Back to top
Bill Todd (TeamB)
Guest





PostPosted: Mon Aug 09, 2004 12:43 pm    Post subject: Re: Nulls in SQL Insert statements Reply with quote



Call the parameter's Clear method to set the parameter to null.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
Back to top
Craig Stuntz [TeamB]
Guest





PostPosted: Mon Aug 09, 2004 1:15 pm    Post subject: Re: Nulls in SQL Insert statements Reply with quote



Bill Todd (TeamB) wrote:

Quote:
Call the parameter's Clear method to set the parameter to null.

...and then manually assign TParam.Bound := TRUE.

-Craig

--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
How to ask questions the smart way:
http://www.catb.org/~esr/faqs/smart-questions.html

Back to top
Matthew Pascoe
Guest





PostPosted: Tue Aug 10, 2004 12:28 am    Post subject: Re: Nulls in SQL Insert statements Reply with quote

Bill,

Thanks for your reply. I will be calling the SP from another SP, not
directly from my application. How do I go about using the Clear method from
within a SP?

Regards,
Matthew


"Bill Todd (TeamB)" <no (AT) no (DOT) com> wrote

Quote:
Call the parameter's Clear method to set the parameter to null.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)



Back to top
Bill Todd (TeamB)
Guest





PostPosted: Tue Aug 10, 2004 3:34 am    Post subject: Re: Nulls in SQL Insert statements Reply with quote

On Tue, 10 Aug 2004 10:28:10 +1000, "Matthew Pascoe"
<mpascoe (AT) stocklogix (DOT) com.au> wrote:

Quote:
How do I go about using the Clear method from
within a SP?

You don't. Just assign NULL to the variable you are passing as a
parameter.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Back to top
Arthur Hoornweg
Guest





PostPosted: Tue Aug 10, 2004 10:31 am    Post subject: Re: Nulls in SQL Insert statements Reply with quote

What's the problem?

INSERT INTO mytable (name,surname,age) values ('SMITH', 'JOHN', NULL);

Alter mytable set age=NULL where name='SMITH'









--
Arthur Hoornweg
(please remove the ".net" from my e-mail address)
Back to top
Matthew Pascoe
Guest





PostPosted: Tue Aug 10, 2004 10:51 pm    Post subject: Re: Nulls in SQL Insert statements Reply with quote

Bill,

Ah, that is what I was missing. I am converting some Delphi code to SP's and
didn't release you could assign a null value to a variable (as it can't be
done in Delphi).

That has solved my problem.

Matthew

"Bill Todd (TeamB)" <no (AT) no (DOT) com> wrote

Quote:
On Tue, 10 Aug 2004 10:28:10 +1000, "Matthew Pascoe"
[email]mpascoe (AT) stocklogix (DOT) com.au[/email]> wrote:

How do I go about using the Clear method from
within a SP?

You don't. Just assign NULL to the variable you are passing as a
parameter.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)



Back to top
Matthew Pascoe
Guest





PostPosted: Tue Aug 10, 2004 10:52 pm    Post subject: Re: Nulls in SQL Insert statements Reply with quote

Craig,

Thanks for your reply.

Matthew
"Craig Stuntz [TeamB]" <cstuntz (AT) nospam (DOT) please [a.k.a. vertexsoftware.com]>
wrote in message news:411778d8 (AT) newsgroups (DOT) borland.com...
Quote:
Bill Todd (TeamB) wrote:

Call the parameter's Clear method to set the parameter to null.

...and then manually assign TParam.Bound := TRUE.

-Craig

--
Craig Stuntz [TeamB] . Vertex Systems Corp. . Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
How to ask questions the smart way:
http://www.catb.org/~esr/faqs/smart-questions.html



Back to top
Matthew Pascoe
Guest





PostPosted: Tue Aug 10, 2004 10:52 pm    Post subject: Re: Nulls in SQL Insert statements Reply with quote

Arthur,

Thanks for your reply.

Matthew
"Arthur Hoornweg" <arthur.hoornweg (AT) wanadoo (DOT) nl.net> wrote

Quote:
What's the problem?

INSERT INTO mytable (name,surname,age) values ('SMITH', 'JOHN', NULL);

Alter mytable set age=NULL where name='SMITH'









--
Arthur Hoornweg
(please remove the ".net" from my e-mail address)



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.