all groups > sql server programming > may 2006 >
You're in the

sql server programming

group:

Help with Sql Statement Where Like Column Query



Help with Sql Statement Where Like Column Query Greg V
5/23/2006 9:57:01 PM
sql server programming: Hi, I need a bit of help figuring out a sql statement.

I have one table filled with static data.

(TableEquip)
Code Desc
----- ------
T37 Tank
T42 Heavy Tank

Then I have data that is pulled hourly

(TableUsers)
User Equip
----- ---------
001 02\T37\W
002 01\T42\T
003 01\T42\W

The goal is to use the first table and the second table to make a view like

(ViewCurrent)
User Equip Desc
----- ---------- -----
001 02\T37\W Tank

My code so far...

SELECT User, Equip, Desc
FROM TableEquip, TableUsers
WHERE ('T37' LIKE Code) AND User = 001

The above works fine statically. I need to make it compare the two tables
so I was thinking...

WHERE (Equip LIKE '%" & Code & "%') AND User = 001

That hasn't worked... It appears that the sql server takes the column name
as the variable, so it never really looks at the data in the column.

I'm guessing the other option if I can't compare the two tables using the
column is to push the data into a variable after some string manipulation,
but I'm not sure how to get there. With that, The Equip field always has two
chars then a \ Then 3-4 chars I want, a \ and two chars.

Anyhow, I'd love to see if there's a fix for this problem... thanks!
RE: Help with Sql Statement Where Like Column Query Omnibuzz
5/23/2006 10:07:01 PM
shouldn't it be..

WHERE (Equip LIKE '%' + Code + '%') AND User = 001


[quoted text, click to view]
RE: Help with Sql Statement Where Like Column Query Greg V
5/23/2006 10:26:01 PM
Omnibuzz, thank you! Yes... I'd forgotten which way it went. Much
appreciated!

[quoted text, click to view]
RE: Help with Sql Statement Where Like Column Query Omnibuzz
5/23/2006 10:39:01 PM
Don't you worry.. It happens to all of us :)

[quoted text, click to view]
AddThis Social Bookmark Button