|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am having trouble searching for a single quote in a column
I have been trying to use SELECT * FROM TABLE WHERE COLUMN LIKE '%'%' THE ESCAPE COMMAND DOES NOT SEEM TO WORK EITHER |
|
#2
|
||||
|
||||
|
Are you trying to select the column names? I could of course be wrong on this, but I think the select will only give you the data IN the table, not the column names.
I was thinking of a way you might be able to do this. I have never done it, but.... First determine the ID from sysobjects that corresponds to your table, then: Code:
SELECT syscolumns.name, syscolumns.id FROM sysobjects JOIN syscolumns ON sysobjects.id = syscolumns.id WHERE sysobjects.id = 123456 --123456 relates to the ID of your table. As for the single quote, it will not search for that character. You will have to use some other character. I wish I could be more helpful! Also, I would think that you would not be able to use the single quote in a column name anyway, but I have not tried it. You could, of course, modify the above code to return all the column names of whichever table(s) you are evaluating. |
|
#3
|
|||
|
|||
|
Sorry,
I didn't explain myself very well I was refering to the data within the column not the column JeffA |
|
#4
|
|||
|
|||
|
Try doubling up the ' in your sql LIKE. MS databases 'escape' the ' character by doubling it. in the sql.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#5
|
|||
|
|||
|
Amazing how simple it is
JeffA |
|
#6
|
||||
|
||||
|
Quote:
LOL you know I thought of that. But the only way I could get that to work in my testing was to have four single quotes, since two right next to each other indicate a zero length string. Is that a workable solution in SQL? |
|
#7
|
|||
|
|||
|
Code:
SELECT * FROM TABLE WHERE COLUMN LIKE '%''%' This shouldn't interpret the inner ' as a zero length string, since the doubled ' are inside a string variable. |
|
#8
|
||||
|
||||
|
Nice tip Thanks!!!!
![]() |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Searching for a single quote |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|