Hi,
i have "req_date" column of "datetime" type in Database table besides
other columns.
From my Web page, i am calling the Stored Procedure with variable
parameter "Search_Dat e" of Varchar(60) type.
the value, i am passing to Stored procedure through "Search_Dat e" is
compared to req_date column of table.
My question is that how to do this comparision of date in WHERE part of
Select statement within Stored Procedure?
Thanks 3 14181
Why are you using a varchar parameter when the correct data type is
datetime? I would fix the front end to use the proper data type, rather
than hack in something on the server side - it will also help to
prevent invalid data and SQL injection attacks.
If you really want to do it on the server, you can CAST() or CONVERT()
to datetime, but that's a workaround, not a solution.
Simon
Use a DATETIME parameter rather than a VARCHAR otherwise you'll just
have to convert the value. Don't rely on implict conversion for date
strings because it is subject to regional settings on the server and
the connection.
Assuming @search_date is a DATETIME:
WHERE req_date = @search_date
or, if you just what to search on the date and ignore the time:
WHERE req_date >= @search_date AND req_date <
DATEADD(DAY,1,@ search_date)
--
David Portas
SQL Server MVP
--
David Portas (RE************ *************** *@acm.org) writes: Use a DATETIME parameter rather than a VARCHAR otherwise you'll just have to convert the value. Don't rely on implict conversion for date strings because it is subject to regional settings on the server and the connection.
It's worth pointing out here that the regional settings that David
are talking about are *not* those of Windows. Instead SQL Server
has its own settings that can affect how date literals are interpreted.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Lloyd Sheen |
last post by:
Below is the output from command window. This shows values of variables and
result of comparison.
Make no sense except to dot.net.
Any ideas??
?pofile
#11/11/2003 12:39:22 PM#
?pdtdbdate
|
by: Stephen |
last post by:
I have to write a .Net application which can compare SQL Databases including
things like: -
DB structure, PK's, FK's,
indexes and types of indexes i.e. should be able to detect if the same index
has cascade set on one db and not on another, or unique on one and not the
other,
Constraints, Triggers, Stored procs, Users, Roles.
I downloaded the SQL Data Compare 3.0 application 14 day trial and it seemed
really good however does a bit more...
|
by: Robin Lawrie |
last post by:
Hi again, another problem!
I've moved from an Access database to SQL server and am now having trouble
inserting dates and times into seperate fields. I'm using ASP and the code
below to get the date and time, but my script is erroring.
'-- Get login date and time
cmdLoginDate = Date()
cmdLoginTime = Time()
|
by: mhk |
last post by:
Hi,
i have "req_date" column of "datetime" type in SQL server database table
besides other columns.
From my Web page, i am calling the Stored Procedure with variable
parameter "Search_Date" of Varchar(60) type.
The value, i am passing to Stored procedure through "Search_Date" is
compared to req_date column of table.
|
by: Adam Knight |
last post by:
Hi all,
I am trying to pass a date parameter into an sql (SQL SERVER) stored
procedure.
Initially i was trying to pass the parameter like so:
cmdReportQuestions.Parameters.Add(New
SqlParameter("@sdt",Request.Form("txtStartDt")))
| |
by: John Wildes |
last post by:
Hello all
I'm going to try and be brief with my question, please tell me if I have the
wrong group.
We are querying transaction data from a DB3 database application. The dates
are stored as text fields. Each date for example 10/31/03 or October 31st
2003 is stored as 10/31/A3 in the system. My reasoning for this is because
they couldn't solve their Y2K problem or this is their solution to it. All
dates prior to 2000 are stored...
|
by: Øyvind Isaksen |
last post by:
I have a page with an optional integer-field, and one asp:calendar control.
I use a stored procedure to save the data in SQL Server.
When all fields contains data, the code works great! But if the user dont
fill in the optional "price-field" (integer value), or if the user dont
choose a date in the asp:calendar control, I get the message "Input string
was not in a correct format".
How do I save "Null" value if the price-field is blank,...
|
by: syntego |
last post by:
We commonly use triggers to log changes to our main tables to
historical log tables.
In the trigger, we create a concatenated string of the old values by
casting them as follows:
CAST(O.MYDATE AS CHAR(30))
When directly updating date fields in the main table, the logged value
gets saved in the format YYYY-MM-DD as expected.
|
by: gderosa |
last post by:
Hey everyone...I need to create a job which occurs once monthly that is based on a stored procedure that contains as a rough example:
CREATE PROCEDURE CompareDate
@CurrentDate datetime
AS
SELECT * FROM Contracts WHERE EndDate LIKE (CURRENT SERVER DATE)
GO
|
by: Brad Pears |
last post by:
I am working on a vb.net 2005 project using sql server 2000 as the backend .
I am having a bit of problems with date variables... Here is the scenario...
I have a table that includes a couple "smalldatetime" fields.
In my class for this table, when inserting new or saving a row in the table,
both of these date values may possibly be empty. (ie I am allowing nulls on
the db side... )
|
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...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |