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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:03:30+00:00 2026-06-16T15:03:30+00:00

I have a stored procedure like this (shortened to the minimum necessary): CREATE PROCEDURE

  • 0

I have a stored procedure like this (shortened to the minimum necessary):

CREATE PROCEDURE [dbo].[proc_Foo]
    -- Add the parameters for the stored procedure here
    @StyleNumber int,
    @App nvarchar(50),
    @User nvarchar(20)
AS
BEGIN
    DECLARE @UserChar varchar(1) = 'U'

    -- User with App
    SELECT [StyleType],
           [Value], 'UA' AS 'DerivedFrom'
    FROM daten.dbo.GridStyleLocal
    WHERE [StyleAssign] = @UserChar
    AND [User] = @User
    AND [StyleNumber] = @StyleNumber
    AND [Application] = @App

    UNION

    -- Global (Basis) with app
    SELECT [StyleType],
           [Value], 'GA' AS 'DerivedFrom'
    FROM basis.dbo.GridStyle
    WHERE [StyleNumber] = @StyleNumber
    AND [Application] = @App
    AND [StyleType] NOT IN (
        SELECT [StyleType]
        FROM daten.dbo.GridStyleLocal
        WHERE [StyleAssign] = @UserChar
        AND [User] = @User
        AND [StyleNumber] = @StyleNumber
        AND [Application] = @App)

    UNION

    -- Scrape missing StyleTypes from Number 0
    SELECT [StyleType],
           [Value], 'G0A' AS 'DerivedFrom'
    FROM basis.dbo.GridStyle
    WHERE [StyleNumber] = 0
    AND [Application] = @App
    AND [StyleType] NOT IN (
        SELECT [StyleType]
        FROM daten.dbo.GridStyleLocal
        WHERE [StyleAssign] = @UserChar
        AND [User] = @User
        AND [StyleNumber] = @StyleNumber
        AND [Application] = @App)
    AND [StyleType] NOT IN (
        SELECT [StyleType]
        FROM basis.dbo.GridStyle
        WHERE [StyleNumber] = @StyleNumber
        AND [Application] = @App)

END

GO

Now StyleNumber 0 is my base style. All properties (StyleType) that are not in another StyleNumber are derived from StyleNumber 0. But now if I include the second SELECT (Global (Basis) with app) when @StyleNumber is set to 0, the DerivedFrom value is GA instead of G0A.

So is there a any kind of conditional, that could exclude this SELECT out of the union if @StyleNumber is 0?

  • 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-16T15:03:31+00:00Added an answer on June 16, 2026 at 3:03 pm

    Not very clear exactly what you need. Assuming you need to get G0A if @StyleNumber = 0 from the second query, change your second select query (– Global (Basis) with app) as follows with the CASE.

    SELECT [StyleType],
           [Value], 
           CASE @StyleNumber WHEN 0 THEN 'G0A' ELSE 'GA' END AS 'DerivedFrom'
    FROM basis.dbo.GridStyle
    --Rest fo the query
    

    NOT to select any records from second select query if @StyleNumber = 0, add CASE to WHERE clause as;

    WHERE [Application]  = 
      CASE @StyleNumber
          WHEN 0 THEN 'This app does not exist' --Give unavailable @App number 
          ELSE @App
      END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say we have stored procedure(s) performing simple operations like this: CREATE PROCEDURE [dbo].[AddNewAuthorReturnID] (
I have stored-procedure in Oracle database like this: create or replace PROCEDURE EDYTUJ_PRACOWNIKA (PR_IMIE
I have a stored procedure like this: CREATE PROCEDURE up_action (@id int ,@group varchar(30)=''
I have a stored procedure that goes like this: ALTER PROCEDURE [dbo].[AuthenticateUser] @AzUserName varchar(20),
I have created a simple stored procedure like this: Alter Proc dbo.s5 ( @id
I have a TSQL stored procedure like this: ALTER PROCEDURE [dbo].[SearchEntityDataNew] @SearchText varchar(100) =
I have created a Stored Procedure, that looks like this: DELIMITER €€ CREATE PROCEDURE
I have a line in my SQL Stored Procedure that looks like this (works
I have a stored procedure with an IN OUT parameter declared like follows: create
I am using SQL Server 2008 R2. I have the stored procedure like this

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.