 |
| SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 25th, 2003, 04:52 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Date problem in insert and update
How can insert the date field BLANK in sql server ?
How can update the date filed BLANK in sql server ?
I want to insert blank date but sql server not insert blank date record why ?
In the sql server date save ie. "01/01/1900"
When I insert BLANK DATE why ?
INSERT CODE
------------------------
isql1="insert into drawings (name,date_recd,dtype,location) values ("
isql2="'" & dname & "',"
isql3="'"& date_recd &"',"
isql4="'"& date_recd &"',"
isql5="'" & dtype & "',"
isql6="'" & location & "')"
isql=isql1+isql2+isql3+isql4+isql5+isql6
cn.Execute isql
UPDATE CODE
-----------------------
usql1="update drawings set "
usql2="name='"& name1 &"',"
usql3="date_recd='"& date_recd &"',"
usql4="location='"& location &"',"
usql5="dtype='"& dtype &"' where dwg_count="&dwg_count
usql=usql1+usql2+usql3+usql4+usql5
cn.execute usql
Please check the date filed.
Mateen
|
|

August 25th, 2003, 09:08 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
|
|
What do you mean by 'blank date'? Specifically, what do you mean by the term 'blank'?. A string (char or varchar) column can take on a value of a zero length string, or the blank character, two meanings I might assign to the term 'blank'. For other datatypes, the term 'blank' really has no meaning.
Specifically, the datetime datatype cannot be blank as I have defined it above. If you attempt to assign a date value of '' (or the string ' '), it will instead take on the value of date 0 , which is 1/1/1900.
When you say 'blank date', do you mean NULL? Any column which has the null attribute set will allow a null value, but null isn't at all the same thing as 'blank' (whatever you might mean by that).
To insert or update a null value in the manner you are attempting, use the keyword 'null' (without quotation marks), e.g.:
Code:
isql1="insert into drawings (name,date_recd,dtype,location) values ("
isql2="'" & dname & "',"
isql3="NULL,"
isql4="'"& date_recd &"',"
isql5="'" & dtype & "',"
isql6="'" & location & "')"
isql=isql1+isql2+isql3+isql4+isql5+isql6
cn.Execute isql
Similarly for your update code.
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
|
|

August 26th, 2003, 12:55 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your response.
Yes I mean NULL, some time I need to insert NULL in the date_Recd and some time I need to insert date in the date_Recd field.
It give the following error.
Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
There are fewer columns in the INSERT statement than values specified in the VALUES clause.
The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
/pweb/tp_drawings/add_drawing2a.asp, line 62
isql1="insert into drawings (name,date_recd,dtype,location) values ("
isql2="'" & dname & "',"
isql3="NULL,"
isql4="'" & date_recd & "',"
isql5="'" & dtype & "',"
isql6="'" & location & "')"
''isql7="insert into sectors (name,sect_area,loc_type) values ("
''isql8="'" & sname & "',"
''isql9="'" & sect_area & "',"
''isql10="'" & loc_type & "')"
isql=isql1+isql2+isql3+isql4+isql5+isql6
cn.Execute isql // line 62
date_recd is only one column. There may be this condition apply ?
if date_Recd="date" then
isql4="'" & date_recd & "',"
else
isql4="NULL,"
if yes how ? I apply this condition but it always inter NULL value.
Quote:
quote:Originally posted by Jeff Mason
What do you mean by 'blank date'? Specifically, what do you mean by the term 'blank'?. A string (char or varchar) column can take on a value of a zero length string, or the blank character, two meanings I might assign to the term 'blank'. For other datatypes, the term 'blank' really has no meaning.
Specifically, the datetime datatype cannot be blank as I have defined it above. If you attempt to assign a date value of '' (or the string ' '), it will instead take on the value of date 0 , which is 1/1/1900.
When you say 'blank date', do you mean NULL? Any column which has the null attribute set will allow a null value, but null isn't at all the same thing as 'blank' (whatever you might mean by that).
To insert or update a null value in the manner you are attempting, use the keyword 'null' (without quotation marks), e.g.:
Code:
isql1="insert into drawings (name,date_recd,dtype,location) values ("
isql2="'" & dname & "',"
isql3="NULL,"
isql4="'"& date_recd &"',"
isql5="'" & dtype & "',"
isql6="'" & location & "')"
isql=isql1+isql2+isql3+isql4+isql5+isql6
cn.Execute isql
Similarly for your update code.
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
|
|
|

August 26th, 2003, 04:42 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:
There are fewer columns in the INSERT statement than values specified in the VALUES clause.
The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
|
You have four columns and five values...
Try this:
Code:
isql1="insert into drawings (name,date_recd,dtype,location) values ("
isql2="'" & dname & "',"
if IsDate(date_recd) then
isql3="NULL,"
else
isql3="'" & date_recd & "',"
end if
isql4="'" & dtype & "',"
isql5="'" & location & "')"
isql=isql1+isql2+isql3+isql4+isql5
|
|

August 26th, 2003, 07:12 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by Jonax
You have four columns and five values...
Try this:
Code:
isql1="insert into drawings (name,date_recd,dtype,location) values ("
isql2="'" & dname & "',"
if IsDate(date_recd) then
isql3="NULL,"
else
isql3="'" & date_recd & "',"
end if
isql4="'" & dtype & "',"
isql5="'" & location & "')"
isql=isql1+isql2+isql3+isql4+isql5
|
Jonax made a little mistake, the If should be like this
Code:
isql1="insert into drawings (name,date_recd,dtype,location) values ("
isql2="'" & dname & "',"
if IsDate(date_recd) then
isql3="'" & date_recd & "',"
else
isql3="NULL,"
end if
isql4="'" & dtype & "',"
isql5="'" & location & "')"
isql=isql1+isql2+isql3+isql4+isql5
Stéphane Lajoie
|
|

August 26th, 2003, 07:31 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:
Jonax made a little mistake
|
... indeed he did ;) - thanks for pointing it out ...
|
|

August 27th, 2003, 04:50 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks
Quote:
quote:Originally posted by stephanel
Quote:
|
quote:Originally posted by Jonax
|
Quote:
You have four columns and five values...
Try this:
Code:
isql1="insert into drawings (name,date_recd,dtype,location) values ("
isql2="'" & dname & "',"
if IsDate(date_recd) then
isql3="NULL,"
else
isql3="'" & date_recd & "',"
end if
isql4="'" & dtype & "',"
isql5="'" & location & "')"
isql=isql1+isql2+isql3+isql4+isql5
|
Jonax made a little mistake, the If should be like this
Code:
isql1="insert into drawings (name,date_recd,dtype,location) values ("
isql2="'" & dname & "',"
if IsDate(date_recd) then
isql3="'" & date_recd & "',"
else
isql3="NULL,"
end if
isql4="'" & dtype & "',"
isql5="'" & location & "')"
isql=isql1+isql2+isql3+isql4+isql5
Stéphane Lajoie
|
|
|
 |