Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

As stated above subject, I would like to do a code as following:

SQL
select UniformGroupID, price from UniformPrice where (datename(YEAR, CONVERT (datetime,EffectiveDate, 103))='2012'
and datename(MONTH, CONVERT (datetime,EffectiveDate, 103))='October')
between (datename(YEAR, CONVERT (datetime,CloseDate, 103)='2999' and datename(MONTH, CONVERT (datetime,CloseDate, 103))='December')


I know I'm wrongly using the BETWEEN command but the concept is something like that so how should I set it or any other command that can be used as BETWEEN command?


Thanks.

N$P
Posted
Comments
Christian Graus 9-Jan-13 3:11am    
This is illegible, I can't even work out what you're trying to do.
singping 9-Jan-13 3:16am    
yes, the above code is wrong just i want to show the concept that i want to display the date which is between 2 different fields (EffectiveDate & CloseDate).
Zoltán Zörgő 9-Jan-13 3:16am    
Try to formulate in English what you want to query, like: Every record from UniformPrice where...
singping 9-Jan-13 3:32am    
I would like to get the value of UniformGroupID & price from a table named UniformPrice where the year & month of effectivedate and closedate is between 2012 to 2999 and October to December.
Maciej Los 9-Jan-13 16:22pm    
1) Do you want to fetch data where both dates (effectivedate and closedate) are between X/2012 and XII/2999?
or
2) Do you want to fetch data where effectivedate is X/2012 and closedate is XII/2999?
or
3) Do you want to fetch data where effectivedate is between X/2012 and XII/2012, and closedate is between X/2999 and XII/2999?

Try this

SQL
SELECT
 UniformGroupID,
 price
FROM
UniformPrice
WHERE
CONVERT (datetime,EffectiveDate, 103) BETWEEN '1/10/2012' AND '31/12/2999'
AND
CONVERT (datetime,CloseDate, 103) BETWEEN '1/10/2012' AND '31/12/2999'


Hope this helps
--RDBurmon
 
Share this answer
 
v4
Comments
singping 9-Jan-13 3:56am    
sorry that i just want the month & year only, how can I do it?
Zoltán Zörgő 9-Jan-13 4:29am    
That's a nonsense. Any date greater or equal to "October 2012" is actually greater or equal to "1. October 2012". Think about it.
RDBurmon 9-Jan-13 4:35am    
Updated a bit . Also Zoltan is correct. Think on it
singping wants this way, try and see
SQL
SELECT
 UniformGroupID,
 price
FROM
UniformPrice
WHERE
DATEPART(yyyy,EffectiveDate) BETWEEN '2012' AND '2999'
AND
DATEPART(mm,CloseDate) BETWEEN '10' AND '12'
 
Share this answer
 
dear please do some practices on sql command at least basic and with operator then ask the questions

http://www.techonthenet.com/sql/between.php[^]


http://www.1keydata.com/sql/sqlbetween.html[^]

http://www.w3schools.com/sql/sql_between.asp[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900