Problem with variable in T-SQL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Surajit Laha

    #1

    Problem with variable in T-SQL

    Hi,

    I want to find out the project names, for the PROJ table and I know
    the Project IDs as a string (comma seperated).

    I tried this:

    ---------------------------
    DECLARE @proj_ids varchar(500)

    SET @proj_ids='(100 ,200)'

    SELECT PROJ_NAME FROM PROJ WHERE PROJ_ID IN + @proj_ids
    ------------------------

    But this throws the error:
    "Incorrect syntax near '+'"

    in Query Analyzer.

    Could someone please point, what I am doing wrong?
    I know, I must be doing something very silly!
  • John Bell

    #2
    Re: Problem with variable in T-SQL

    Hi

    Check out the excellent article at:
    Se våra kampanjer på mobiler, abonnemang och tv- och streampaket | Telenor


    John

    "Surajit Laha" <s_laha@rediffm ail.com> wrote in message
    news:ba8ee108.0 310140529.3af4d d96@posting.goo gle.com...[color=blue]
    > Hi,
    >
    > I want to find out the project names, for the PROJ table and I know
    > the Project IDs as a string (comma seperated).
    >
    > I tried this:
    >
    > ---------------------------
    > DECLARE @proj_ids varchar(500)
    >
    > SET @proj_ids='(100 ,200)'
    >
    > SELECT PROJ_NAME FROM PROJ WHERE PROJ_ID IN + @proj_ids
    > ------------------------
    >
    > But this throws the error:
    > "Incorrect syntax near '+'"
    >
    > in Query Analyzer.
    >
    > Could someone please point, what I am doing wrong?
    > I know, I must be doing something very silly![/color]


    Comment

    • Erland Sommarskog

      #3
      Re: Problem with variable in T-SQL

      [posted and mailed, please reply in news]

      Surajit Laha (s_laha@rediffm ail.com) writes:[color=blue]
      > I want to find out the project names, for the PROJ table and I know
      > the Project IDs as a string (comma seperated).
      >
      > I tried this:
      >
      > ---------------------------
      > DECLARE @proj_ids varchar(500)
      >
      > SET @proj_ids='(100 ,200)'
      >
      > SELECT PROJ_NAME FROM PROJ WHERE PROJ_ID IN + @proj_ids
      > ------------------------
      >
      > But this throws the error:
      > "Incorrect syntax near '+'"
      >
      > in Query Analyzer.
      >
      > Could someone please point, what I am doing wrong?
      > I know, I must be doing something very silly![/color]

      Yes, you are inventing your own syntax. SQL Server is not clever enough
      to understand that.

      Although, John recommended one article on my web site, I like to
      recommend another. Look at

      to see a function that will help you out.

      --
      Erland Sommarskog, SQL Server MVP, sommar@algonet. se

      Books Online for SQL Server SP3 at
      http://www.microsoft.com/sql/techinf...2000/books.asp

      Comment

      • Surajit Laha

        #4
        Re: Problem with variable in T-SQL

        Thanks a lot to you people!!!

        The article at the URL pointed, was fabulous!
        I really liked it and solved a lot of confusions of mine...

        Thanks guys.

        -surajit

        Comment

        Working...