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 2000 Forums
 SQL Server Development (2000)
 can i use like in dynamic sql

Author  Topic 

marconi8
Yak Posting Veteran

73 Posts

Posted - 2003-05-12 : 11:01:25
anybody knows what is the syntax of building dynamic sql with like functions

i have a var


DECLARE @VAR NVARCHAR(1000)

SET @VAR='(FIELD_1 LIKE '%a%')'

i was trying " quotas but nothing helps


how to use d.sql with like ,


thanks


X002548
Not Just a Number

15586 Posts

Posted - 2003-05-12 : 11:16:37
I'm thinking you're looking fo:


DECLARE @sql varchar(8000), @SelectionCriteria char(1)

SELECT @SelectionCriteria = 'U'

SELECT @sql = 'SELECT * FROM Orders Where ShipCountry LIKE '
+ ''''
+ @SelectionCriteria
+ '%'
+ ''''
EXEC(@sql)



....and 800!



Brett

8-)
Go to Top of Page

dhw
Constraint Violating Yak Guru

332 Posts

Posted - 2003-05-12 : 14:58:28
I was struggling with this yesterday and finally came up with a solution..that I discovered while searching the forums here. Rather than using the single quotes and having to add extra single quotes to escape them...I found a message that described recommended using char(39) instead. Like,

Set @Where = ' WHERE myColumn LIKE '
Set @Where = @Where + char(39) + @InputParam + '%' + char(39)

....dhw

Go to Top of Page

marconi8
Yak Posting Veteran

73 Posts

Posted - 2003-05-12 : 15:40:40
listen, thanks for helping,

you know !, at this moment i realy cannot understand is microsoft sql normally workable with web

i was developming my pags with firebird, i never have this problems which i have with microsoft sql

all day i cannot find solution for my scripts, my scripts have logic structure , but i have noticed that microsoft sql damage all my script structure, at this moment i very very nervous because i cannot normally programing

i must to add milions checks for quotas and double quotas in my scripts, eeehhhhh this situation killed me, all day and zero work result, this is for the first to me when my work is stopped and cannot normally go forward

on firebird i have only one string

selectlimit ($sql, $var1,$var2)

this string with mssql now grows to stored procedure and milions code strings

--------------------------------------------------------
very bad things at this moment are in my php scripts, hm , but i will try to find answer to my question, where is power of mssql using it with internet
--------------------------------------------------------

at this moment mssql do only damages on my php scripts, maybe i am wrong , maybe !!! but today on very important my questions i received answers = you cannot or it is impossible, i was confused receiving this king of answers, because i was talking about very elemntar things

all my post readers , dont be angry to me, i only little nervous because my scripts now must be resized to millions compromises



















Go to Top of Page

dhw
Constraint Violating Yak Guru

332 Posts

Posted - 2003-05-12 : 17:56:47
Sorry to hear about your problems. I know the feeling.

I have only used php with mySQL....not with MS Sql Server....so I cannot help there.

good luck.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-05-12 : 18:12:56
marconi8,

You can use single quotes or even double quotes (will want to look up QUOTED_IDENTIFIER in BOL though) with dynamic sql. Have you tried Brett's example?

Tara
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-05-12 : 18:39:23
Try using ADO and stored procedures. Then you just pass parameters. Concatenating strings together to execute them is NOT a good idea, IMHO.

Look at SET @@ROWCOUNT to limit your queries dynamically, wihtout needing the TOP operator.

- Jeff

Edited by - jsmith8858 on 05/12/2003 18:40:02
Go to Top of Page
   

- Advertisement -