Re: Formatting string in WHERE clause

Discussion in 'ASP .Net' started by Lee Simpson, Jul 18, 2003.

  1. Lee Simpson

    Lee Simpson Guest

    Here is a potential solution:

    declare @Criteria varchar(700)
    declare @Comma int

    set @Criteria = 'White,Green'

    create table #tmp (Name varchar(100))

    while (CharIndex(',', @Criteria)>0)
    begin
    set @Comma = CharIndex(',', @Criteria)

    insert into #tmp select substring(@Criteria, 0, @Comma)
    select @Criteria = substring(@Criteria, @Comma+1, datalength(@Criteria))
    end --while

    insert into #tmp select @Criteria

    select *
    from authors a,
    #tmp b
    where a.au_lname = b.Name



    Hope this helps, always glad to help out a fellow South African...

    Regards
    Lee Simpson
    UK




    "Corrie Taljaard" <> wrote in message
    news:bf8h49$cc0$...
    > Hi ,
    > I'm having a problem formatting a string to be used in the WHERE clause.
    > Here is my code
    >
    > DECLARE @Criteria varchar(700)
    >
    > 'The formatting that i tried without success
    > Using 2 ( ' ) hypens next to each other
    > SET @Criteria = ' ' + ''LSACONXB'' + ',' + ''ALTLCNXB'' + ',' +
    > ''CAGECDXH''+ ',' + ''REFNUMHA'' + ' '
    >
    > Using ( " ) double quotes
    >
    > SET @Criteria = ' ' + "LSACONXB" + ',' + "ALTLCNXB" + ',' + "CAGECDXH"

    +
    > ',' + "REFNUMHA" + ' '
    >
    > Using a combination of ( " ) double quotes and ( ' ) hypen
    > SET @Criteria = ' ' + '"LSACONXB"' + ',' + '"ALTLCNXB"' + ',' +
    > '"CAGECDXH"' + ',' + '"REFNUMHA"' + ' '
    >
    > The testing code with IN
    > WHERE (Static.dbo.intWindow.GuiID = @GUIWindowID)
    >
    > This is the code part used with a variable
    > --AND (Static.dbo.intField.FieldName IN (@Criteria))
    >
    > That has to coincide with the following codepart
    > --AND (Static.dbo.intField.FieldName IN

    ('LSACONXB','ALTLCNXB','CAGECDXH'))
    >
    >
    > Any help appriciated
    > Thanks in advance
    >
    >
    >
    >
    >
     
    Lee Simpson, Jul 18, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jan
    Replies:
    2
    Views:
    1,480
    Mike Treseler
    Dec 16, 2004
  2. bxbxb3

    "else process" clause

    bxbxb3, May 26, 2005, in forum: VHDL
    Replies:
    3
    Views:
    694
    combinational.logic $ soc-ip.com
    May 27, 2005
  3. Andre Alexander Bell

    String formatting with the format string syntax

    Andre Alexander Bell, Sep 14, 2010, in forum: Python
    Replies:
    9
    Views:
    524
    Andre Alexander Bell
    Sep 15, 2010
  4. Andrew Berg
    Replies:
    13
    Views:
    1,359
    Andrew Berg
    Jul 11, 2011
  5. Victor Hooi
    Replies:
    3
    Views:
    144
    Chris Kaynor
    Nov 27, 2013
Loading...

Share This Page