Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Table rows containing asterisk wildcard character

Author  Topic 

amcb
Starting Member

2 Posts

Posted - 2012-10-23 : 05:07:29
Hi,

I have a MSSQL database table that can contain rows with a wildcard character ("*") in the column values. I am trying to create a SQL select statement using the LIKE command to return the rows that contain the wildcard character where the wildcard character substitutes one or many of the characters in my comparrison value. Below is a basic example ...I'm sure there is a way to do this, but I need some help on how to construct the syntax:

table_A contains a row with the following columns and values:

Column_1: *
Column_2: 11*
Column_3: Fred

I have tried the following command - expecting this to match against the above row, but this does not return any rows:

SELECT Column_3 FROM table_A WHERE ('123' LIKE column_1) AND ('111' LIKE column_2)

Can anyone offer some advise on how I can construct the correct syntax?

Thanks,
Andrew

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-10-23 : 05:38:08
[code]
WHERE ('123' LIKE replace(column_1, '*', '%'))
AND ('111' LIKE replace(column_2, '*', '%'))
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

amcb
Starting Member

2 Posts

Posted - 2012-10-23 : 06:00:17
thanks khtan, that works perfectly.

Go to Top of Page
   

- Advertisement -