Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1057409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:51:48+00:00 2026-05-16T17:51:48+00:00

Is it possible to pass a Dictionary<String, String> (or something similar; like a key/value

  • 0

Is it possible to pass a Dictionary<String, String> (or something similar; like a key/value pair) as an argument to a stored procedure on an MS SQL 2005 server?

I’m looking for a practical example.

Update

This question lead me to ask this one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:51:48+00:00Added an answer on May 16, 2026 at 5:51 pm

    You need a way to split and process the string in TSQL, there are many ways to do this. This article covers the PROs and CONs of just about every method:

    “Arrays and Lists in SQL Server 2005 and Beyond, When Table Value Parameters Do Not Cut it” by Erland Sommarskog

    You need to create a split function. This is how a split function can be used:

    SELECT
        *
        FROM YourTable                               y
        INNER JOIN dbo.yourSplitFunction(@Parameter) s ON y.ID=s.Value
    

    I prefer the number table approach to split a string in TSQL but there are numerous ways to split strings in SQL Server, see the previous link, which explains the PROs and CONs of each.

    For the Numbers Table method to work, you need to do this one time table setup, which will create a table Numbers that contains rows from 1 to 10,000:

    SELECT TOP 10000 IDENTITY(int,1,1) AS Number
        INTO Numbers
        FROM sys.objects s1
        CROSS JOIN sys.objects s2
    ALTER TABLE Numbers ADD CONSTRAINT PK_Numbers PRIMARY KEY CLUSTERED (Number)
    

    Once the Numbers table is set up, create this split function:

    CREATE FUNCTION [dbo].[FN_ListToTableRows]
    (
         @SplitOn  char(1)      --REQUIRED, the character to split the @List string on
        ,@List     varchar(8000)--REQUIRED, the list to split apart
    )
    RETURNS TABLE
    AS
    RETURN 
    (
        ----------------
        --SINGLE QUERY-- --this will return empty rows, and row numbers
        ----------------
        SELECT
            ROW_NUMBER() OVER(ORDER BY number) AS RowNumber
                ,LTRIM(RTRIM(SUBSTRING(ListValue, number+1, CHARINDEX(@SplitOn, ListValue, number+1)-number - 1))) AS ListValue
            FROM (
                     SELECT @SplitOn + @List + @SplitOn AS ListValue
                 ) AS InnerQuery
                INNER JOIN Numbers n ON n.Number < LEN(InnerQuery.ListValue)
            WHERE SUBSTRING(ListValue, number, 1) = @SplitOn
    );
    GO 
    

    You can now easily split a CSV string into a table and join on it. To accomplish your task, sif you can pass in two parameters, one of keys one of values, then create your procedure like this:

    CREATE PROCEDURE StoredProcedureName
    (
         @Params1  int
        ,@Array1   varchar(8000)
        ,@Params2  int
        ,@Array2   varchar(8000)
    )
    AS 
    
    DECLARE @YourTable table (col1 int, col2 int)
    
    INSERT INTO @YourTable
            (col1, col2)
        SELECT
            a1.ListValue, a2.ListValue
            FROM dbo.FN_ListToTableRows(',',@Array1)            a1
                INNER JOIN dbo.FN_ListToTableRows(',',@Array2)  a2 ON a1.RowNumber=a2.RowNumber
    
    select * from @YourTable
    
    GO
    

    test it out:

    exec StoredProcedureName 17,'127,204,110,198',7,'162,170,163,170'
    

    OUTPUT:

    (4 row(s) affected)
    col1        col2
    ----------- -----------
    127         162
    204         170
    110         163
    198         170
    
    (4 row(s) affected)
    

    or if you want to pass in a single parameter key value pair use something like this:

    CREATE PROCEDURE StoredProcedureName
    (
         @KeyValueList  varchar(8000)
    )
    AS 
    
    DECLARE @YourTable table (RowKey varchar(500), RowValue varchar(500))
    
    INSERT INTO @YourTable
            (RowKey, RowValue)
        SELECT
            LEFT(y.ListValue,CHARINDEX(',',y.ListValue)-1),RIGHT(y.ListValue,LEN(y.ListValue)-CHARINDEX(',',y.ListValue))
            FROM dbo.FN_ListToTableRows(';',@KeyValueList) y
    
    SELECT * FROM @YourTable
    
    GO
    

    run it:

    exec StoredProcedureName 'a,5;b,BBB;abc,xyz'
    

    OUTPUT:

    RowKey  RowValue
    ------- -----------
    a       5
    b       BBB
    abc     xyz
    
    (3 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to pass TargetActivity.class to another activity and do something like: //
Alright, I'm trying to pass a Dictionary, where key = int, and value =
Possible Duplicate: How to serialize Dictionary<string, string> through WCF? How to pass a dictionary
Possible Duplicate: Pass a PHP string to a Javascript variable (including escaping newlines) Hy,
Is it possible to pass *args to string.format? I have the following function: @classmethod
I'm wondering if is possible pass types by argument in Java. Let me explain
Is it possible to pass an argument to the listener when a button is
I have a name value pair array in Javascript (just like form.SerializeArray()) which i
Possible Duplicate: pass parameter in g:remoteLink as result of javascript function I am trying
Possible Duplicate: pass data from Action To Another Action I have a view in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.