Unix Technical Forum

Sql query with a stringfunction

This is a discussion on Sql query with a stringfunction within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi... I have a problem. I need a query that can handle to search throu a string, here called ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 04:15 AM
majsen
 
Posts: n/a
Default Sql query with a stringfunction

Hi...

I have a problem. I need a query that can handle to search throu a string, here
called mylist. if lF08.postNr is in mylist all is ok.

mylist="115, 116, 117, 118, 119, 120"

Something like this

strSQ = "SELECT DISTINCT * from lF08, m08 where
instr(lF08.postNr,mylist) AND lF08.memberNr=m08.memberNr order by ort DESC"

I know i can't use the function instr, but how can i solve this. Is there
a function for this? I use sql-server 2000

Regards mikael
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 04:15 AM
Simon Hayes
 
Posts: n/a
Default Re: Sql query with a stringfunction


"majsen" <mikael@home.staertesjoen.se> wrote in message
news:58316675.0409130359.31a71d13@posting.google.c om...
> Hi...
>
> I have a problem. I need a query that can handle to search throu a string,
> here
> called mylist. if lF08.postNr is in mylist all is ok.
>
> mylist="115, 116, 117, 118, 119, 120"
>
> Something like this
>
> strSQ = "SELECT DISTINCT * from lF08, m08 where
> instr(lF08.postNr,mylist) AND lF08.memberNr=m08.memberNr order by ort
> DESC"
>
> I know i can't use the function instr, but how can i solve this. Is there
> a function for this? I use sql-server 2000
>
> Regards mikael


Assuming myList is a string, then one way is to build the query string on
the front end:

strSQ = "
SELECT DISTINCT *
from lF08 join m08
onlF08.memberNr=m08.memberNr
where lF08.postNr in (" + myList + ")
order by ort DESC"

This article explains how to use a server-side approach:

http://www.sommarskog.se/arrays-in-sql.html

Simon


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 04:16 AM
mikael Hellström
 
Posts: n/a
Default Re: Sql query with a stringfunction

Thanks!
Nice pice of code...
Regards mikael



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:32 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com