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

  • Home
  • SEARCH
  • 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 7495955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:24:26+00:00 2026-05-29T18:24:26+00:00

I have a SQL statement that displays the following values, but the number of

  • 0

I have a SQL statement that displays the following values, but the number of rows can be anything.

   SELECT NameID,Name,ValueID,Value FROM Options WHERE OptionID = 10000

Which results to:

 NameID  |  Name   |  ValueID  |  Value

 100     |  Color  |  10000    |  Black
 101     |  Size   |  10005    |  Large

Or sometimes even:

 NameID  |  Name   |  ValueID  |  Value

 100     |  Color  |  10000    |  Black
 101     |  Size   |  10005    |  Large
 102     |  Height |  10009    |  Tall
 103     |  Width  |  10006    |  Wide

I’m trying to write a Stored Procedure that can allow me to check if ALL of these value’s exist based on OptionID

Therefore,

  1. The statement would allow an input of OptionID of course to only show all the options inside the Options table for this OptionID
  2. The statement would allow an input of multiple paired values for NameID and ValueID

The general logic needed would be something like this:

if ALL NameID and ValueID Pairs with-in an OptionID Exists
(as shown above in the results) 
   Then Return 'Unique Combination'
     Else Return 'Combination Exists'

Boolean would be fine as well. I’ve tried using a PIVOT to see if it can be done like this, but that was a bit more than i think i needed, but maybe not.. Any suggestions?

  • 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-29T18:24:29+00:00Added an answer on May 29, 2026 at 6:24 pm

    You can use an if exists statement.

    if exists(SELECT NameID,Name,ValueID,Value FROM Options WHERE OptionID = @optionID and NameId = @NameID and ValueID = @ValueID)
    begin
       --do whatever you want
    end
    else
    begin
       --do whatever else you want
     end
    

    Updated answer

    Declare @Loop as int,@POS int, @PAirs varchar(max),@CurrentPair varchar(max)
    Declare @NameID as int,@ValueID as int, @Loop2 as int,@Pos2 int
    
    SELECT @Pos = CHARINDEX(';', @Pairs, 1)
    print @Pos
    SELECT @Loop = CASE WHEN LEN(@Pairs) > 0 THEN 1 ELSE 0 END
        WHILE (SELECT @Loop) = 1
        BEGIN
            SELECT @Pos = CHARINDEX(';', @Pairs, 1)
            IF @Pos > 0
                BEGIN
                    set @CurrentPair = SUBSTRING(@Pairs, 1, @Pos - 1) --Here it is a comma delimited string such as 100,20000
                    set @Pairs = SUBSTRING(@Pairs, @Pos + 1, LEN(@Pairs) - @Pos) --This takes the current pair away from original string
    
                    SELECT @Loop2 = CASE WHEN LEN(@CurrentPair) > 0 THEN 1 ELSE 0 END
                    While (Select @Loop2) = 1
                        Begin
                            SELECT @Pos2 = CHARINDEX('2', @CurrentPair, 1)
                            If @Pos2 > 0
                                Begin
                                    set @NameID = SUBSTRING(@CurrentPair, 1, @Pos2 - 1)
                                    set @ValueID = SUBSTRING(@CurrentPair, @Pos2 + 1, LEN(@CurrentPair) - @Pos2)
    
                                    if exists(SELECT NameID,Name,ValueID,Value FROM Options 
                                                WHERE NameId = @NameID and ValueID = @ValueID)
                                        begin
                                            --pair found
                                        end
                                    else
                                        begin
                                            --pair not found
                                        end
    
                                End
                            Else
                                Begin
                                    set @Loop2 = 0
                                End
                        End
                END
            ELSE
                BEGIN
                    set @Loop = 0
                END
        END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to following SQL Statement that I want to conver to LINQ Select
I have a SQL statement that looks like: SELECT [Phone] FROM [Table] WHERE (
I have an sql statement that is supposed to return 2 rows. the first
I have an annoying SQL statement that seem simple but it looks awfull. I
Anyone have a PL-SQL statement that i can use to generate database & tables
I have the following SQL statement SELECT [Motor] ,[Time] FROM [logger].[dbo].[motor] WHERE day([Time]) =
I have a sql statement that uses Difference => http://msdn.microsoft.com/en-us/library/ms188753.aspx I do this in
I have an SQL statement that I'm executing through OleDb, the statement is something
I have an sql statement that currently is just returning all the end parent
Let's say I have an SQL statement that's syntactically and semantically correct so it

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.