473,700 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using the AS clause in a SQL stored proc -- problem using datetime column

I'm trying to concatenate fields in SQL stored proc for use in text
field in asp.net dropdownlist. I'm running into a problem when I try
to use a DateTime field, but can't find the answer (so far) on the
Internet. Was hoping someone here would know?

My sql stored proc:

SELECT AnomalyID, DateEntered + ', ' + Station + ', ' + Problem As
'SelectInfo'
FROM tblAnomaly
WHERE WorkOrder=@varW O AND Signoff=Null
ORDER BY DateEntered

but I get the error:
The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

I'm not the brightest bulb on the block, so any clues greatly
appreciated!

Thanks, Kathy
Jul 20 '05 #1
3 4000
Kathy,

You need to convert the DateEntered field. Also pay attention that you can
not compare a field to NULL using "=", use "is" operator insted.
Try this:

SELECT AnomalyID,
convert(varchar , DateEntered, 100) + ', ' + Station + ', ' + Problem
As 'SelectInfo'
FROM tblAnomaly
WHERE WorkOrder = @varWO AND Signoff is null
ORDER BY DateEntered

Shervin

"KathyB" <Ka**********@a ttbi.com> wrote in message
news:75******** *************** **@posting.goog le.com...
I'm trying to concatenate fields in SQL stored proc for use in text
field in asp.net dropdownlist. I'm running into a problem when I try
to use a DateTime field, but can't find the answer (so far) on the
Internet. Was hoping someone here would know?

My sql stored proc:

SELECT AnomalyID, DateEntered + ', ' + Station + ', ' + Problem As
'SelectInfo'
FROM tblAnomaly
WHERE WorkOrder=@varW O AND Signoff=Null
ORDER BY DateEntered

but I get the error:
The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.

I'm not the brightest bulb on the block, so any clues greatly
appreciated!

Thanks, Kathy

Jul 20 '05 #2
Thanks, Shervin. And thanks for the quick reply!!!

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
Kathy,

I forgot to tell you about the third parameter of CONVERT. This is the style
used to convert datetime type to string. Check Books Online to get the
complete list of acceptable styles.

Shervin

"Kathy Burke" <ka**********@a ttbi.com> wrote in message
news:3f******** *************@n ews.frii.net...
Thanks, Shervin. And thanks for the quick reply!!!

Kathy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #4

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

Similar topics

7
10237
by: Alex Vorobiev | last post by:
hi there, i am using sql server 7. below is the stored procedure that is giving me grief. its purpose it two-fold, depending on how it is called: either to return a pageset (based on page number and page size), or to return IDs of previous and next records (based on current record id). the problem is, that the order in which records are inserted into the temp table is inconsistent, even though the calling statement and the order by is...
2
2332
by: jaYPee | last post by:
I have an existing query from MS Access that I want to convert it to SQL Server Stored Proc. My problem is on how to convert the WHERE clause. This is the query from MS Access: SELECT SchYrSemCourseJoin.SchYrSemCourseID, Students.IDNo, & ", " & & " " & AS Name, Program.ProgramTitle, Program.ProgramDesc, SchYrSem.SchYr, SchYrSem.Sem, SchYrSem.Year, SchYrSem.Section AS Section1,
10
3005
by: Jozef de Veuster | last post by:
Hi, I'm trying to create a Stored Procedure that returns a recordset, but I want to be able to choose the ORDER BY clause in mijn parameter list of the Stored Procedure. Since CASE .. WHEN can only be used in the SELECT clause, I came up with the following: -- BEGIN SCRIPT -- DECLARE @blah AS VARCHAR(20) SET @blah = 'DOSSIER_CODE'
9
5275
by: joun | last post by:
Hi all, i'm using this code to insert records into an Access table from asp.net, using a stored procedure, called qry_InsertData: PARAMETERS Long, Long, Text(20), Long, DateTime; INSERT INTO Table ( ID, Cod, CodArt, Q1, DataUscita ) VALUES (pID, pCod, pCod, pQ1, pDataUscita);
1
2771
by: Mok | last post by:
Hello, I want to pull information from a table in sql server, bind it to a grid and update those values. I would like to know the best way to do it. I used the configure data adapter wizard and it came up with a crazy stored proc. As in this example I would only update and : CREATE PROCEDURE . ( @Description varchar(1000),
5
4397
by: ujjc001 | last post by:
two variables declared in my proc: @DATE_RANGE_START as datetime, @DATE_RANGE_END as datetime, When I execute my SP it takes 34 seconds. When I change the variables to: @DATE_RANGE_START1 as datetime, @DATE_RANGE_END1 as datetime,
8
2800
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table, I have a where clause which states : where PermitID like @WorkType order by WorkStart DESC
0
7665
MMcCarthy
by: MMcCarthy | last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access. Angle brackets <> are used in place of some syntax elements you must supply. The description of these elements will be in the contained in the angle brackets. Square brackets are used to show which parts are optional. Basic SELECT query SELECT <field list> FROM <table/query name(s)>
6
2943
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1) Constraint pk_table1 Primary Key,
0
8731
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8975
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5904
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4408
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3095
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2031
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.