ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 3rd, 2003, 03:32 PM
msuarun msuarun is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 3 msuarun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Null insertion in Microsoft SQL

Hey All,

I am using Microsoft SQL Server

I am stuck up with this prob for some time. I have a data entry form. If the user submits the form without entering any data, the record should be inserted with null entries for the respective fields.

But when i execute the INSERT SQL query with these null values, it gives me an error.

This is vat I am doing:

<%
.....
address = request.form("address")
if request.form("Age")= "" then
ageValue=""
.....
.....
%>
I use these values in SQL query

This is the SQL statement when the above is executed
" INSERT INTO tblStatistics (Age,address) VALUES (, aaa)"

Because of no value for age, the query is not gettin executed. I have also tried
<%
if request.form("Age")= "" then
ageValue=null
....
%>

I dont want a 0, I want a nul entry (<null>).
Could someone throw some light on how to set the age field to null?

Reply With Quote
  #2  
Old November 3rd, 2003, 09:11 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,829 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 20 h 23 m 12 sec
Reputation Power: 765
Try ageValue=null instead of ageValue=""

Reply With Quote
  #3  
Old November 3rd, 2003, 11:21 PM
pda8333 pda8333 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 216 pda8333 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 6 m 31 sec
Reputation Power: 5
you an an error because you did not have a value for Age in your Insert statement.
Code:
INSERT INTO tblStatistics (Age,address) VALUES (null, aaa)" 
__________________
Hope this helps.

Mike
Royal Selangor Pewter

"I have not failed. I've just found 10,000 ways that won't work."
- Thomas Alva Edison (1847-1931)

Reply With Quote
  #4  
Old November 4th, 2003, 08:24 AM
msuarun msuarun is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 3 msuarun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by Doug G
Try ageValue=null instead of ageValue=""



I have tried that too, please find that in my first posting.

Also, incase my scenario is not clear:

I am not directly inserting the values. I am storing the value of age and address in the variables "ageValue" and "address". This I give as an input to the Values part of the query statement. This is what i do:

sSQL1 = "INSERT INTO tblStatistics (Age,address) Values (" &ageValue& "," &address& ")"

Since ageValue is not able to hold the null value, I get the query statement mentioned in my first posting

Reply With Quote
  #5  
Old November 4th, 2003, 09:27 AM
jstrohofer jstrohofer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Cincinnati, OH USA
Posts: 111 jstrohofer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 3 sec
Reputation Power: 5
Well try breaking up your SQL statement to account for this then...it may be a bit more tedious, but it will produce your end result.

You have:

sSQL1 = "INSERT INTO tblStatistics (Age,address) Values (" &ageValue& "," &address& ")"


What you should do is:

sSQL1 = "INSERT INTO tblStatistics (Age,address) Values ("

if ageValue = "" OR isnull(ageValue) then
sSQL1 = sSQL1 & "NULL, "
else
sSQL1 = sSQL1 & ageValue & ", "
end if

sSQL1 = sSQL1 & "'" & address & "' ) "

I am adding the single quotes around the address because I will assume it is a string instead of a number. If it is a number, take them out.

Try that and see how it works out

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Null insertion in Microsoft SQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway