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
 General SQL Server Forums
 New to SQL Server Programming
 character issue

Author  Topic 

musclebreast
Yak Posting Veteran

77 Posts

Posted - 2014-12-11 : 06:19:33
Hi,
I have the following SQL:




Select

a.DataID

From

(select

A1.ID as DataID

from LLAttrData A1, DTree A2

where A1.DefID = 131790
and A1.AttrID = 2
and A1.ID = A2.DataID
and A1.VerNum = A2.VersionNum
and SUBSTRING('(A1.ValStr=''test'')',1,LEN('(A1.ValStr=''test'')'))) a


I get the following error:

An expression of non-boolean type specified in a context where a condition is expected, near ')'.

I know it's because of this expression:

SUBSTRING('(A1.ValStr=''test'')',1,LEN('(A1.ValStr=''test'')'))


My problem is that this '(A1.ValStr=)' is always in qotation marks and comes from another software. Howevermy golas is it to remove the quotation marks in order to run my SQL. But it seems there is a problem with this qotations marks:

A1.ValStr=''test''

I hope you can help me?

Kind regards,

Lara




James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-12-11 : 08:21:46
What do you want it to be? Even after stripping the extra single quotes, you need to equate the substring to something; i.e., you have to have a logical expression that will evaluate to true or false. So you need something like
and SUBSTRING(Something here) = 'SomethingElseHere'
Go to Top of Page

musclebreast
Yak Posting Veteran

77 Posts

Posted - 2014-12-11 : 09:28:20
OK,
this should be the result:

(A1.ValStr ='test')

In my test I get the right result:

Select SUBSTRING('(A1.ValStr =''test'')',1,LEN('(A1.ValStr =''test'')'))


As my result is part of a SQL statement it doesn't work...I really don't know why, because it seems that my query is not wrong. Has anybody an idea. I am desperate...

Cheers...

Lara
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-12-11 : 09:48:40
JamesK asked the right question. What is your answer?
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-12-12 : 15:08:54
I think you are trying to mix a character string and a query. You cannot do something like this:
SELECT * FROM TBL WHERE 'COL1 = 5' -- wrong
You either need to make the entire query dynamic SQL (which comes with its own baggage and security risks) or parse the string that you get to find what condition you need to append to the where clause.
Go to Top of Page
   

- Advertisement -