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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. use a string by reference?

use a string by reference?

Scheduled Pinned Locked Moved Database
databasecomtoolsquestion
3 Posts 2 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.
  • B Offline
    B Offline
    BlackDice
    wrote on last edited by
    #1

    I think there should be a way to do this. In the calling program, I have a list of numbers that I'm building in an sql statement so that the statement looks like this: "SELECT firstname FROM tblPerson WHERE personid in (9,2,4)" that works fine, but I need to use this as a stored procedure now and I need to be able to send in "(9,2,4)" as parameter. Is there a way I can make the sql use the string by reference as regular sql like this: SELECT firstname FROM tblPerson WHERE personid in @idlist where @idlist is a varchar string that I passed in from my app? My articles BlackDice

    B S 2 Replies Last reply
    0
    • B BlackDice

      I think there should be a way to do this. In the calling program, I have a list of numbers that I'm building in an sql statement so that the statement looks like this: "SELECT firstname FROM tblPerson WHERE personid in (9,2,4)" that works fine, but I need to use this as a stored procedure now and I need to be able to send in "(9,2,4)" as parameter. Is there a way I can make the sql use the string by reference as regular sql like this: SELECT firstname FROM tblPerson WHERE personid in @idlist where @idlist is a varchar string that I passed in from my app? My articles BlackDice

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

      Nevermind. I got it to work. i just turned the whole sql statement into a string, saved it to a variable and called exec() on the variable My articles BlackDice

      1 Reply Last reply
      0
      • B BlackDice

        I think there should be a way to do this. In the calling program, I have a list of numbers that I'm building in an sql statement so that the statement looks like this: "SELECT firstname FROM tblPerson WHERE personid in (9,2,4)" that works fine, but I need to use this as a stored procedure now and I need to be able to send in "(9,2,4)" as parameter. Is there a way I can make the sql use the string by reference as regular sql like this: SELECT firstname FROM tblPerson WHERE personid in @idlist where @idlist is a varchar string that I passed in from my app? My articles BlackDice

        S Offline
        S Offline
        Shawn_H
        wrote on last edited by
        #3

        Black Dice, You can create a sql Server function that takes a delimited list as a parameter and returns a table. then in your select list you join onto this function SELECT firstname, lastname FROM employee e INNER JOIN fn_MyFUnction(@DelimitedList) f On e.ID = F.ID "Never Code by Coincidence" -- Andy Hunt

        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