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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:38:07+00:00 2026-06-15T01:38:07+00:00

I have a Conditions table that looks like this : Conditions ConditionID MappingID VariableID

  • 0

I have a Conditions table that looks like this :

Conditions

  • ConditionID
  • MappingID
  • VariableID
  • CompareToVariableID
  • ConditionOperator ( can be == or <> )
  • ConjunctionOperator ( can be && or || )
  • ConjunctionOrder

Now I have a SP that I want to implement these conditions on depending on MappingID.

If a MappingID is selected, all mapped conditions should be checked before anything happens in my SP.

SELECT * 
FROM Conditions
WHERE MappingID = @MappingID
ORDER BY ConjunctionOrder

For example if a certain MappingID had three rows in the Conditions table then :

IF VARIABLEID CONDITIONOPERATOR COMPARETOVARIABLEID CONJUNCTIONOPERATOR --row1
VARIABLEID CONDITIONOPERATOR COMPARETOVARIABLEID CONJUNCTIONOPERATOR  --row2
VARIABLEID CONDITIONOPERATOR COMPARETOVARIABLEID --row3 (ignore ConjunctionOperator for last row)
BEGIN
   --my code goes here
END
ELSE
BEGIN
   --my code here
END

I would like to know how I can implement the IF statement.

  • 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-15T01:38:09+00:00Added an answer on June 15, 2026 at 1:38 am

    One way of doing it is like this (these are the steps in your stored procedure)

    1. Take your conditions off the Conditons table and produce a special booolean expression out of it. You can do it by using a cursor over your SELECT query from your post. You should convert your variable IDs so that they won’t mix with the variable values (you’ll see later what I mean). Let’s suppose your query returned:
    |-----------------------------------------------------------------------------------------|
    |VariableID |COmpareToVariableID |ConditionOperator |ConjunctionOperator |ConjunctionOrder|
    |-----------|--------------------|------------------|--------------------|----------------|
    |A          |B                   |==                |&&                  |1               |
    |C          |D                   |>> (NE)           |                    |2               |
    |-----------|--------------------|------------------|--------------------|----------------|
    

    Your expression (kept in a local SP variable) should be:

    SELECT 1 WHERE #A# = #B# AND #C# >> #D#
    

    In other words you add SELECT 1 WHERE at the beginning and relpace condition operator == with = and conjunction operator && with ‘AND’, and || with ‘OR’

    1. Now you do a cursor query over your Variables table. In each loop you replace the names of the variables with its values (i.e. #A# is replaced with A value). At the end your expression should look like ‘SELECT 1 WHERE 1=2 AND 3<>3’.

    2. You use sp_executesql to execute your dynamically created query. You can put the output in an OUTPUT parameter and check it in your IF statment in your SP.

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

Sidebar

Related Questions

I have a table of invoices that looks like this: InvoiceDate InvoiceNumber PaidDate PayStatus
I have a table that looks like this: |Condition|Session|Time| | A| 1| 100| |
I have something that looks like this: my $report = new ReportGenerator; #custom object
I have an AR query that looks like this user.books.joins(:authors).where(:authors => {:id => [1,2,3]},
I have two tables. First table looks like this: Table: Records rid | user
I have a query using the Containable behavior in cakephp that looks like this
I have a query that looks like this: SELECT * FROM A INNER JOIN
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a two tables that look like this (this is an example of
Situation looks like this: We have product 'A123' and we have to remember lowest

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.