Simple TSQL question

Simple TSQL question

Post by Terence Durnin » Fri, 04 Jun 1999 04:00:00



Hello;

How can select the rows where one column is a substring of another?  I try:

select * from table1 where column1 like '%' + column2 + '%'

but I only get the columns where column1 = column2

Thanks;
Terence Durning

 
 
 

Simple TSQL question

Post by Roy Harv » Fri, 04 Jun 1999 04:00:00


Terence,

Quote:>How can select the rows where one column is a substring of another?  I try:

>select * from table1 where column1 like '%' + column2 + '%'

>but I only get the columns where column1 = column2

If column2 is declared CHAR and the value is shorter than the column,
this is what I would expect; CHAR will give trailing blanks, and LIKE
will only accept a match that includes the blanks.  If it is char,
replace it with the expression RTRIM(column2).

Roy

 
 
 

Simple TSQL question

Post by Terence Durnin » Fri, 04 Jun 1999 04:00:00


Thanks for the answers guys, the rtrim did the trick!


Quote:> Terence,

> >How can select the rows where one column is a substring of another?  I
try:

> >select * from table1 where column1 like '%' + column2 + '%'

> >but I only get the columns where column1 = column2

> If column2 is declared CHAR and the value is shorter than the column,
> this is what I would expect; CHAR will give trailing blanks, and LIKE
> will only accept a match that includes the blanks.  If it is char,
> replace it with the expression RTRIM(column2).

> Roy

 
 
 

1. Simple TSQL question

    I hope this is the right place to ask this, I imagine it will be easy
for many of you. I need a add a bunch of columns to various tables in a
SQL7, SP3 environment, so I thought I'd just write a script. I think I'm
close, but I have some syntax wrong somewhere. I have the following to try
to add a column (bit, no nulls):
ALTER TABLE table_name
 ADD COLUMN col_name bit NOT NULL

and Query Analyzer returns:
Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'COLUMN'.

I've tried various combinations of parenthesis and quotes, but that hasn't
worked. What am I missing here? Thanks!

Matt

2. Errors on linux, not enough memory?

3. SQL7, SIMPLE SIMPLE SIMPLE question

4. Faircom Toolbox/Special Edition/Ctree

5. TSQL SIMPLE PROBLEM

6. Importing MDF files

7. TSQL simple function problem

8. Query

9. nettiquette question...where to post TSQL questions (MSSQL)?

10. Simple Set statement this is very simple question

11. Simple simple ADO question

12. HELP! simple question need simple answer

13. VB5 Pro Masked Edit control - A simple, simple question