Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL:what is wrong in following query

SQL:what is wrong in following query

Scheduled Pinned Locked Moved Database
databasequestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xodeblack
    wrote on last edited by
    #1

    what is wrong in following query. datatype of @Name is text. @Name is parameter passing in stored procedure

    select * from students
    where first_name in ( + @Name + )

    B A 2 Replies Last reply
    0
    • X xodeblack

      what is wrong in following query. datatype of @Name is text. @Name is parameter passing in stored procedure

      select * from students
      where first_name in ( + @Name + )

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Which error message do you get?


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

      X 1 Reply Last reply
      0
      • B Blue_Boy

        Which error message do you get?


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

        X Offline
        X Offline
        xodeblack
        wrote on last edited by
        #3

        Error: Msg 102, Level 15, State 1, Procedure GetFinancialInfo, Line 48 Incorrect syntax near ')'.

        S 1 Reply Last reply
        0
        • X xodeblack

          Error: Msg 102, Level 15, State 1, Procedure GetFinancialInfo, Line 48 Incorrect syntax near ')'.

          S Offline
          S Offline
          Sebastian Br
          wrote on last edited by
          #4

          I would take a look on the SQL statement directly before executing.

          1 Reply Last reply
          0
          • X xodeblack

            what is wrong in following query. datatype of @Name is text. @Name is parameter passing in stored procedure

            select * from students
            where first_name in ( + @Name + )

            A Offline
            A Offline
            Ashfield
            wrote on last edited by
            #5

            You cannot use an IN with a variable. Either use dynamic sql or, my preferred method, use a function to split the list into a table variable and join on that. A quick google will give you examples, but here is a starter

            CREATE FUNCTION [dbo].[fn_DelimitedSplit]
            (
            @TextToSplit VARCHAR(8000), @Delimiter VARCHAR(255)
            )
            RETURNS @SplitKeyword TABLE (Keyword VARCHAR(8000),seq int identity)
            AS
            BEGIN
            DECLARE @Word VARCHAR(255)

            WHILE (CHARINDEX(@Delimiter, @TextToSplit, 1)>0)
            BEGIN
            SET @Word = SUBSTRING(@TextToSplit, 1 , CHARINDEX(@Delimiter, @TextToSplit, 1) - 1)
            SET @TextToSplit = SUBSTRING(@TextToSplit, CHARINDEX(@Delimiter, @TextToSplit, 1) + 1, LEN(@TextToSplit))
            INSERT INTO @SplitKeyword(Keyword) VALUES(@Word)
            END

            INSERT INTO @SplitKeyword(Keyword) VALUES(@TextToSplit)
            return
            END

            Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups