473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Simple query

I know this is super-basic, but I'm a newbie and I can't get it to work...

I'm trying to call a stored procedure that has a datetime as one of its
parameters. How the heck do I get a datetime?? I'd even settle for knowing I
was declaring variables correctly...

DECLARE @Date datetime (right?)
???
EXEC usp_AddRequest 313,'E',@Date,'QUAL'
^^^^^ <- this is the parameter that wants to be a
datetime

How do I make Date correspond to an actual date/time? How do I assign it to
be equal to SELECT GETDATE()? Why doesn't SET @DATE = SELECT GETDATE() work?
And why the heck is it so hard to find the answers online?? I've Googled
endlessly and found nothing...

--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cyberspace.org |
Jul 20 '05 #1
2 4357
Christopher Benson-Manica <at***@nospam.cyberspace.org> spoke thus:
DECLARE @Date datetime (right?)
???
EXEC usp_AddRequest 313,'E',@Date,'QUAL'
^^^^^ <- this is the parameter that wants to be a
datetime


Okay, this one's straight out of the transact SQL book, and it doesn't work
either...
SET @Date=CAST('1999-01-17 11:47:40' AS datetime)

It insists that it can't convert a varchar to a datetime... whyyyyy? :(

--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cyberspace.org |
Jul 20 '05 #2

"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in message
news:bj**********@chessie.cirr.com...
Christopher Benson-Manica <at***@nospam.cyberspace.org> spoke thus:
DECLARE @Date datetime (right?)
???
EXEC usp_AddRequest 313,'E',@Date,'QUAL'
^^^^^ <- this is the parameter that wants to be a datetime
Okay, this one's straight out of the transact SQL book, and it doesn't

work either...
SET @Date=CAST('1999-01-17 11:47:40' AS datetime)

It insists that it can't convert a varchar to a datetime... whyyyyy? :(

--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cyberspace.org |


The format of your date string is not always recognized correctly by SQL
Server:

declare @date datetime

/* Conversion error */
set dateformat dmy
set @date = CAST('1999-01-17 11:47:40' AS datetime)
select @date

/* No conversion error */
set dateformat mdy
set @date = CAST('1999-01-17 11:47:40' AS datetime)
select @date

Both the following formats are 'safe' and always interpreted consistently by
SQL Server, so using either one will work for you:

'1999-01-17T11:47:40'
'19990117 11:47:40'

To answer your previous post, this should work:

DECLARE @Date datetime
SET @Date = getdate()
EXEC usp_AddRequest 313,'E',@Date,'QUAL'

In this case, date formatting is irrelevant because you are always working
with datetime values.

Simon
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: unixman | last post by:
As usual, it is 2:00am, and I'm pulling my hair out, finally resorting to posting in the newsgroups for help. :) Simple problem, in theory. Given table "map": CREATE TABLE map ( entry_id...
6
by: Eddie Smit | last post by:
field- field- surname town ---- ---- john NY john Vegas john Boston eddie Boston eddie New Orleans eddie NY
2
by: Mrs Howl | last post by:
I have a query that just reads one table and appends to an output table, one-for-one. No criteria. It's not a Total query (i.e. no group by). It normally run run in minutes, but gets horribly...
1
by: j.mandala | last post by:
I created a simple link between two tables in a query. TableA has Social Security numbers stored as Long Integer Data. (I imported this table). The Join is between these two fields Table ...
3
by: Don Sealer | last post by:
I'm guessing this is pretty simple however not simple enough for me. I'm developing a database to track expenses, income, banking transactions, etc. I have a very simple query with four fields,...
2
by: Don Wash | last post by:
Hi All! I've been searching everywhere for a simple sample of producing a bar graph using CrystalReport by specifying SQL Query, and I've found none of it! I find so many complex samples with so...
3
by: John Baker | last post by:
Hi:7 Newby here to ASP, and using the ASP.NET Web Matrix development tool. While that tool looks great for a Newby, I have run into a snag. I have an HTML Text Box which I have named HireInput,...
27
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
2
by: Fendi Baba | last post by:
I created a person table with various fields such as Suffix, Salutation, etc, Some of these fields may not be mandatory for example suffix. In the actual table itself, I only have a field for...
9
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.