SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


RE:


Author
Message
@puyinc
@puyinc
SSC Veteran
SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)SSC Veteran (201 reputation)

Group: General Forum Members
Points: 201 Visits: 49

Hi, recently I needed to pass some null value as parameteres to a DateTime field, I was using SQL Server 2k and C# VS 2003.

I tried using DBNull and others values but none fo them worked for me.

What I did at the end was to set a default value of null in the database field, and didn't pass the parameter when I didn't have it, of course it added a little bit of logic when building the query.

Is there anyway to pass null value in the param???



Kindest Regards,

@puy Inc
Doug S.
Doug S.
SSChasing Mays
SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)SSChasing Mays (613 reputation)

Group: General Forum Members
Points: 613 Visits: 333
To pass in a null to some stored procs (with older Vb6/ADO code) you can do this:

1) The VB code puts 1/1/1900 in the date and the proc converts it to null.

2) the proc code is shown below.
...
set @NullDate = convert(smalldatetime, '1/1/1900')

if @aTestTime =@NullDate set @aTestTime = null
...
Then your insert/update statement in the proc uses @aTestTime normally and this will put a null in the date field.

For our other code that generates insert and update statements just use null as you would in query analyzer.

Good luck



Doug
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search