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 8758511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:34:02+00:00 2026-06-13T14:34:02+00:00

I have two variables like: @FieldName @values Those two variables hold values like: @FieldName

  • 0

I have two variables like:

@FieldName 
@values

Those two variables hold values like:

  • @FieldName – contains [a],[b],[c],[d]
  • @values – contains 5,6,7,8

Now I need to retrieve the data of column 'b' & 'd' only.

How can we get b=6 & d=8?

Thanks in advance.

  • 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-06-13T14:34:04+00:00Added an answer on June 13, 2026 at 2:34 pm

    well I hate to do such a things on SQL Server, but

    declare @FieldName nvarchar(max) = '[a],[b],[c],[d]'
    declare @values nvarchar(max) = '5,6,7,8'
    declare @i int, @j int, @break int
    declare @a nvarchar(max), @b nvarchar(max), @result nvarchar(max)
    
    select @break = 0
    
    while @break = 0
    begin
        select @i = charindex(',', @FieldName), @j = charindex(',', @values)
    
        if @i > 0 and @j > 0
        begin
            select @a = left(@FieldName, @i - 1), @b = left(@values, @j - 1)
    
            select @FieldName = right(@FieldName, len(@FieldName) - @i), @values = right(@values, len(@values) - @j)
        end
        else
        begin
            select @a = @FieldName, @b = @values, @break = 1
        end
    
        if @a in ('[b]', '[d]')
            select @result = isnull(@result + ' & ', '') + @a + '=' + @b
    

    end

    select @result
    

    You can also put all this list into temporary/variable table and do join.

    select *
    from
    (
        select T.<yourcolumn>, row_number() over (order by T.<yourcolumn>) as rownum
        from <temptable1> as T
    ) as F
        inner join
        (
            select T.<yourcolumn>, row_number() over (order by T.<yourcolumn>) as rownum
            from <temptable2> as T
        ) as V on V.rownum = F.rownum
    

    Or, even better, you can pass parameters into sp in xml form and not in distinct lists

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two variables. weekStartDate and startDate. they both hold essentially the same timestamp:
I have two float variables that are equal, I retrieve them by PHP and
I have two variables like Question_type and Answer_type in JavaScript. I have a hidden_field
I have two variables which have values that can be in both. I would
I have two variables, work.dir and my.file . This means the user would like
I have two variables which are comma separated lists. I would like to join
This one's probably easy: I have two variables: $sender_id $receiver_id Those ID's are stored
I have two variables like : <script language=javascript type=text/javascript> var count = 1; calc_my_project_
I have anonymous type variable which i am populating like that(i have two variables
I have two Integer variables like int Max = 10; int limit = 5;

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.