469,088 Members | 1,265 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,088 developers. It's quick & easy.

Using LIKE with underscore and forward slash..

Hello All,

DDL Statements:

CREATE TABLE [dbo].[Table1] (
[MyDate] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
I have a varchar column which represents dates in YYYYMMDD and MM/DD/YY
formats. If I query using:

SELECT MyDate FROM Table1
WHERE DOB LIKE '________'

Why aren't the dates in MM/DD/YY returned ? Is the / a special
character in T-SQL ?

Thanks in advance

Jul 23 '05 #1
1 6007
On 8 Mar 2005 06:14:40 -0800, hharry wrote:

(snip)
I have a varchar column which represents dates in YYYYMMDD and MM/DD/YY
formats.
Hi hharry,

That's a bad idea to start with. Please use a datetime column for dates.
If I query using:

SELECT MyDate FROM Table1
WHERE DOB LIKE '________'

Why aren't the dates in MM/DD/YY returned ? Is the / a special
character in T-SQL ?


What's in the DOB column? Your DDL includes only the MyDate column!

In case this is a type and you really meant
WHERE MyDate LIKE '________'
then I can't reproduce the problem:

-- Copied from your post
CREATE TABLE [dbo].[Table1] (
[MyDate] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL
) ON [PRIMARY]
GO
-- Inserted my own sample data
insert Table1 (MyDate) values ('20050308')
insert Table1 (MyDate) values ('08/03/05')
go
-- Copied from your post; changed DOB to MyDate
SELECT MyDate FROM Table1
WHERE MyDate LIKE '________'
go
-- Cleanup
drop table Table1
go

If I run the script above, both rows are returned.

Could you post some SQL to enable me to reproduce the problem on my
computer?

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Frank | last post: by
3 posts views Thread by COHENMARVIN | last post: by
4 posts views Thread by Jon Weston | last post: by
2 posts views Thread by Greg Collins [Microsoft MVP] | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.