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
 SQL Server 2005 Forums
 Express Edition and Compact Edition (2005)
 Foward Slash within SQL Database /

Author  Topic 

swiftdeal
Starting Member

3 Posts

Posted - 2008-08-29 : 06:59:38
Hi

Newbie 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 Mayne
Swiftdeal

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-29 : 07:52:15
Use brackets

SELECT * FROM Table1 WHERE [R44322/554] = 'muhahaha'


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

swiftdeal
Starting Member

3 Posts

Posted - 2008-08-29 : 08:02:44
Thanks for your reply Peso

But, the R44322/554 is the data not the field name.

Roger Mayne
Swiftdeal
Go to Top of Page

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"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-29 : 08:26:25
quote:
Originally posted by swiftdeal

Hi

Newbie 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 Mayne
Swiftdeal


Post the query you used

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

swiftdeal
Starting Member

3 Posts

Posted - 2008-08-29 : 08:47:45
Peso

That'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 Mayne
Swiftdeal
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-29 : 08:51:55
quote:
Originally posted by swiftdeal

Peso

That'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 Mayne
Swiftdeal


Post the query anyway. Let us see if we can modify it without using dynamic sql

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -