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.
Author |
Topic |
swiftdeal
Starting Member
3 Posts |
Posted - 2008-08-29 : 06:59:38
|
HiNewbie Alert!!I have an SQL database that has a forward slash within the fields. The data is something like R44322/554.I am using an ASP .NET form to search the database. I can search on any other fields, fill a dataset and display the data (including the slash data). However, if I search the field with the slash in it, I receive an error...Invalid column name 'R44322'.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'R4434'.I need to somehow stop the SQL query from looking for the slash. Apparently, I need to search for CHAR(47) instead of the slash.Not sure what to do next.Any ideas??? Hope I've explained myself properly. Thanks in advance for any help offered.Roger MayneSwiftdeal |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-08-29 : 07:52:15
|
Use bracketsSELECT * FROM Table1 WHERE [R44322/554] = 'muhahaha' E 12°55'05.25"N 56°04'39.16" |
|
|
swiftdeal
Starting Member
3 Posts |
Posted - 2008-08-29 : 08:02:44
|
Thanks for your reply PesoBut, the R44322/554 is the data not the field name.Roger MayneSwiftdeal |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-08-29 : 08:10:24
|
Ok, so you are buildig a dynamic string to search for value R44322/554 ?Just enclose the value in single quotes...SELECT * FROM Table1 WHERE Col1 = 'R44322/554'If you don't have single quotes when searching a this value,the SQL parser will try to find those records where Col1 equals the value of column R44322 divided by 554.SELECT * FROM [Table1] WHERE [Col1] = [R44322] / 554 E 12°55'05.25"N 56°04'39.16" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-29 : 08:26:25
|
quote: Originally posted by swiftdeal HiNewbie Alert!!I have an SQL database that has a forward slash within the fields. The data is something like R44322/554.I am using an ASP .NET form to search the database. I can search on any other fields, fill a dataset and display the data (including the slash data). However, if I search the field with the slash in it, I receive an error...Invalid column name 'R44322'.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'R4434'.I need to somehow stop the SQL query from looking for the slash. Apparently, I need to search for CHAR(47) instead of the slash.Not sure what to do next.Any ideas??? Hope I've explained myself properly. Thanks in advance for any help offered.Roger MayneSwiftdeal
Post the query you usedMadhivananFailing to plan is Planning to fail |
|
|
swiftdeal
Starting Member
3 Posts |
Posted - 2008-08-29 : 08:47:45
|
PesoThat's solved the problem. Hadn't spotted that all other fields had single quotes around the criteria. I'm building the SQL query dynamically, and the code wasn't easy for me to follow. Once you pointed it out, it seems obvious now!Thanks so much for your prompt replies. Much appreciated.Roger MayneSwiftdeal |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-29 : 08:51:55
|
quote: Originally posted by swiftdeal PesoThat's solved the problem. Hadn't spotted that all other fields had single quotes around the criteria. I'm building the SQL query dynamically, and the code wasn't easy for me to follow. Once you pointed it out, it seems obvious now!Thanks so much for your prompt replies. Much appreciated.Roger MayneSwiftdeal
Post the query anyway. Let us see if we can modify it without using dynamic sqlMadhivananFailing to plan is Planning to fail |
|
|
|
|
|
|
|