Friday, March 23, 2012

Newbie Question

Can i use >= and LIKE together in a SELECT...WHERE.
SELECT * FROM X WHERE Y >= LIKE '1234%'Hi
You can not do this. What are you trying to achive?
It would help if you posted example DDL and data such as
http://www.aspfaq.com/etiquett___e.asp?id=5006 and
example data as insert statements
http://vyaskn.tripod.com/code.___htm#inserts
along with queries and what you are trying to achieve.
John
"LacOniC" <iletisim@.bigfoot.com> wrote in message
news:eUCImzqMFHA.3928@.TK2MSFTNGP09.phx.gbl...
> Can i use >= and LIKE together in a SELECT...WHERE.
> SELECT * FROM X WHERE Y >= LIKE '1234%'
>|||EXISTS (SELECT FORUM_MEMBERS.M_DATE WHERE M_DATE = 20050322124227)
I want to select members after a specific M_DATE. But i don't want to write
hour section, so i wanted to use
LIKE. I2m newbie as i said, maybe think wrong. =)|||Well. =)
EXISTS (SELECT FORUM_MEMBERS.M_DATE WHERE M_DATE = 20050322000000)|||Hi
You didn't post DDL, therefore I assume M_Date is a datetime. Datetime data
will assume midnight (00:00:00.000) if the time portion is specified
therefore
SELECT FORUM_MEMBERS.M_DATE WHERE M_DATE >= '20050322'
AND M_DATE < '20050323'
are all occurences on the given date.
You could convert to string aswell although the first method should be
quicker.
SELECT FORUM_MEMBERS.M_DATE WHERE CONVERT(CHAR(8),M_DATE,112) = '20050322'
John
"LacOniC" <iletisim@.bigfoot.com> wrote in message
news:%23M0wJDrMFHA.2252@.TK2MSFTNGP15.phx.gbl...
> EXISTS (SELECT FORUM_MEMBERS.M_DATE WHERE M_DATE = 20050322124227)
> I want to select members after a specific M_DATE. But i don't want to
> write hour section, so i wanted to use
> LIKE. I2m newbie as i said, maybe think wrong. =)
>|||Sorry. M_DATE value type is nvarchar in database.|||Hi
You can thererfore use the second example without the need to convert it to
char, although you may have to use LEFT to get the first 8 characters. This
assumes that you make sure that the format YYYYMMDD is always entered in
full.
SELECT FORUM_MEMBERS.M_DATE WHERE LEFT(M_DATE,8) = '20050322'
As you are using this format the following will also work for anything on or
after the given date.
SELECT FORUM_MEMBERS.M_DATE WHERE LEFT(M_DATE,8) >= '20050322'
John
John
"LacOniC" <iletisim@.bigfoot.com> wrote in message
news:%2328ZqyrMFHA.3076@.TK2MSFTNGP14.phx.gbl...
> Sorry. M_DATE value type is nvarchar in database.
>|||Thank you John!..sql

No comments:

Post a Comment