473,390 Members | 1,189 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,390 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 4356
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.