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
 Transact-SQL (2005)
 Is there a function to split out where sentence?

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2007-09-14 : 09:31:32
I code to get "where" sentence like below:

where city = "New York", order_num = '123556', ordered_by = 'John Smith'

How to make a function to split out each parameters like:

city = "New York"
order_num = '123556'
ordered_by = 'John Smith'

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2007-09-14 : 09:39:34
replace(',','')

replace(',',char(13))



Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-14 : 09:43:21
SELECT * FROM dbo.fnParseList(',', Col1)



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

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2007-09-17 : 12:18:37
You can find the function here.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-17 : 12:36:29
Won't work, though, if one of the parameters contains the delimiter - i.e. the parser does not understand quoted sections.

SELECT * FROM dbo.fnParseList(',', 'foo = ''foo,bar''')

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-18 : 01:53:04
quote:
Originally posted by Sun Foster

I code to get "where" sentence like below:

where city = "New York", order_num = '123556', ordered_by = 'John Smith'

How to make a function to split out each parameters like:

city = "New York"
order_num = '123556'
ordered_by = 'John Smith'



Why do you want to split WHERE?

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2007-09-18 : 02:40:29
Doesn't look like a SQL WHERE, exactly. Perhaps that's the reason?

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-18 : 04:10:38
quote:
Originally posted by Kristen

Doesn't look like a SQL WHERE, exactly. Perhaps that's the reason?

Kristen


So does it sound "Beautify my sql code"?

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2007-09-18 : 05:51:43
Well, I'm only guessing, but I assumed this was some sort of "list" of criteria created by a front end, which then needs splitting and AND's adding to get a suitable WHERE clause for SQL.

The OP could give us a description of the problem to be solved, and no doubt we could all come up with different solutions then

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-18 : 06:05:25
<<
but I assumed this was some sort of "list" of criteria created by a front end, which then needs splitting and AND's adding to get a suitable WHERE clause for SQL.
>>

Then I would advise OP not to concatenate sql statements at front and make use of stored procedures with parameters or http://www.sommarskog.se/dyn-search.html

Madhivanan

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

- Advertisement -