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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:42:06+00:00 2026-06-15T17:42:06+00:00

In my sql script I have this: insert into @res select case when x

  • 0

In my sql script I have this:

insert into @res
    select
    case
            when x = 'tblDoll' then (...)
            when x = 'tblCar' then (...)
            when x = 'tblRocket' then
                if rel_table_id = @old_id
                    (select x.price from tableInDb x where x.id = rel_table.toy_id)
    end
        from rel_table
        where my_toy_id = @toy_id

@old_id is an input parameter.

But something in the if returns syntax error.
rel_table_id is the id of rel_table. How to put an if condition there?

  • 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-15T17:42:07+00:00Added an answer on June 15, 2026 at 5:42 pm

    JOIN the two tables, with more nested CASE expression like so:

    INSERT INTO @res
    SELECT 
      CASE
        WHEN x = 'tblDoll'               THEN  (...)
        WHEN x = 'tblCar'                THEN  (...)
        WHEN x = 'tblRocket'             THEN  
          CASE WHEN rel_table_id = @old_id THEN  x.price END
      END
    FROM rel_table t1
    INNER JOIN tableInDb x ON x.id = rel_table.toy_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

now i have this form post script <? if(isset($_POST['baslik'])) { $sql = INSERT INTO
I have a SQL script that will insert a long string into a table.
I have script files with thousands of sql INSERT INTO lines. Some of these
I have this query running in my PHP script: $insertQuery = "INSERT INTO blog_articles
I have this SQL: INSERT INTO v3_peers (torrent, peer_id, ip, ipv6, port, smoke_ip, uploaded,
I have this sql script DECLARE @XmlStr XML SET @XmlStr = '<EmployeeID> <Employee>48f9194f-8d46-e111-8849-0050569445f1</Employee> <Employee>7d725561-8d46-e111-8849-0050569445f2</Employee>
I have a script task that executes a dynamically created SQL restore statement. This
I have a SQL script that populates a temp column and then drops the
I have the Execute SQL Script package that contains the script to insert about
I have this script: DELETE FROM [Tags] WHERE Id = CONVERT(uniqueidentifier, '7373D1A0-CB6A-4207-87C4-AE2939FD20C0'); GO INSERT

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.