c#


sql query for getting data between 2 dates which are explicitly given


I want to get data betwenn 2 dates and these dates are supplied by the user.
what i did is as follows
CREATE PROCEDURE getattndncchart
(
#date1 varchar(50),
#date2 varchar(50)
)
AS
SELECT * FROM Tbl_Date WHERE Date BETWEEN #date1 AND #date2
but am not getting the result. pls help me out.
is your Date should be different type instead of varchar(50), ?
I am never used procedures, so maybe I am wrong. Maybe something like this?
CREATE PROCEDURE getattndncchart
#date1 date,
#date2 date
AS
BEGIN
SELECT * FROM Tbl_Date WHERE [Date] BETWEEN #date1 AND #date2
END;
Also, Date in your WHERE clause needs to be surrounded by [ ] (since it is a reserved word).
It looks like you have several errors here:
1) As Andrew points out, you can't compare dates that are not the correct type. So you should parse the values as a date or datetime into the stored procedure from your application.
2) In order to do a comparison of dates, you must have another date type to compare it to. For example:
CREATE PROCEDURE getattndncchart
(
#date1 date,
#date2 date
)
AS
DECLARE #curdate date = CURRENT_TIMESTAMP
SELECT *
FROM Tbl_Date
WHERE #curdate BETWEEN #date1 AND #date2

Related Links

deserialize xml array with namespace
Can I merge two IEnumerable<string> to IEnumerable<string,string>
Populating ListBox.DataTextField
Non breaking spaces(160) instead of spaces (32) in tableadapter of strongly typed dataset
How can I delete the pages in an enormous PDF that do not contain a certain word at the top of the page? Hopefully in C#
c# ZipFile CompressLevel not work
Problems updating Google Translate cookie in Chrome
How to use more than one DataContext
C# archiving using 7zip, keeps hanging on wildcard call
C# Image/Bitmap Superclass/Subclass Casting anomaly
Link Button in Updatepanel causes page refresh
c# windows phone 8 app, change system volume
How to access a textbox in a form from other form [closed]
HTTPWebRequest with gzip compression
Entity Framework & Portable Class Library
Use Style in TreeView HierarchicalDataTemplate

Categories

HOME
gulp
gcc
postgresql-9.3
webvr
window.open
gap-system
latex
glsl
mailchimp
kendo-asp.net-mvc
qt4
rethinkdb
jpql
jetbrains
opengrok
lambda-calculus
template10
google-street-view
audio-streaming
django-rest-auth
custom-component
restructuredtext
rollupjs
cloudformation
large-files
uibarbuttonitem
osgi-bundle
circle
flickr
tunnel
geocomplete
jslider
google-chrome-console
redbean
electron-packager
autodesk-data-management
contenteditable
google-chrome-storage
monaca
ear
wink
r-commander
senti-wordnet
dmalloc
netlink
recurring
nimbus
usps
clique
stdlist
sqldataadapter
app-data
play-json
random-sample
adempiere
cloud-storage
roslyn-code-analysis
callfire
mergecursor
connection-timeout
shunting-yard
quickfixn
step
telerik-appbuilder
twitter-finagle
farpoint-spread
email-headers
power-management
boofcv
pechkin
nokogiri
google-email-audit-api
facebook-winjs-sdk
capitalization
clgeocoder
digg
sipdroid
netduino
iphone-maps
for-xml
retrospectiva
scala-designer
projectgen
file-icons
managed-code

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile