| View previous topic :: View next topic |
| Author |
Message |
Matthew Pascoe Guest
|
Posted: Mon Aug 09, 2004 5:28 am Post subject: Nulls in SQL Insert statements |
|
|
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
|
Posted: Mon Aug 09, 2004 12:43 pm Post subject: Re: Nulls in SQL Insert statements |
|
|
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
|
Posted: Mon Aug 09, 2004 1:15 pm Post subject: Re: Nulls in SQL Insert statements |
|
|
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
|
Posted: Tue Aug 10, 2004 12:28 am Post subject: Re: Nulls in SQL Insert statements |
|
|
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
|
Posted: Tue Aug 10, 2004 3:34 am Post subject: Re: Nulls in SQL Insert statements |
|
|
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
|
Posted: Tue Aug 10, 2004 10:31 am Post subject: Re: Nulls in SQL Insert statements |
|
|
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
|
Posted: Tue Aug 10, 2004 10:51 pm Post subject: Re: Nulls in SQL Insert statements |
|
|
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
|
Posted: Tue Aug 10, 2004 10:52 pm Post subject: Re: Nulls in SQL Insert statements |
|
|
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...
|
|
| Back to top |
|
 |
Matthew Pascoe Guest
|
Posted: Tue Aug 10, 2004 10:52 pm Post subject: Re: Nulls in SQL Insert statements |
|
|
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 |
|
 |
|