Exclude data

  • I Have a problem with my sql

    I have this sql statement as doing sums in Customer based on the following requirements. The sql statement Works fine.

    SELECT DISTINCT BV.[Code]

    ,count(C.[Potential Business Volume]) AS AntalTotal

    FROM [LF_Drift].[dbo].[x$Business Volume] AS BV INNER JOIN [LF_Drift].[dbo].[x$Customer] AS C

    ON BV.[Code] = C.[Potential Business Volume]

    INNER JOIN [LF_Drift].[dbo].[x$User Setup] AS US

    ON C.[Salesperson Code] = us.[User ID]

    GROUP BY BV.Code, C.[Potential Business Volume]

    ORDER BY BV.Code

    Sql make the following display:

    Code, AntalTotal

    A, 105

    B, 324

    C, 981

    D, 858

    E, 35821

    X 320

    Additional function:

    What I want is, when BV. [Code] comes to E, it has to check if A, B, C or D is in the field C. [Current Business Volume].

    If True then it must be counted in the sum.

    Hope my question is understandable.

    Thanks in advance.

  • Hi mite,

    Welcome to the forum 🙂

    Can you rephrase your question. If you can,could you please put the expected output you want.

    That will atleast help us 🙂

  • Well, I´m not sure if I can rephrase my question, but I try.

    I have 3 tables

    Table: User Setup (as US)

    Fields: User ID, Department

    Table contains all our users and where they work (department)

    Table: Business Volume (as BV)

    Fields: Code

    Table contains

    A + 5 MIO

    B 2 - 5 MIO

    C 0,5 - 2 MIO

    D - 0,5 MIO

    E NEUTRAL

    X UØNSKET

    Table: Customer (as C)

    Fields: salesperson code, potential business volume, current business volume

    Salesperson code is also in the table User Setup.

    The fields potential business volume, current business volume can be filled with a Code from table Business Volume. It can also be a blank field.

    I show you the complete sql statement, I hope not it is confusing.

    [font="Courier New"]SELECT DISTINCT BV.[Code]

    ,count(C.[Potential Business Volume]) AS AntalTotal

    ,(SELECT COUNT(c1.[Potential Business Volume])

    FROM [LF_Drift].[dbo].[Leasing Fyn$Customer] AS C1

    INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$User Setup] AS US

    ON C1.[Salesperson Code] = us.[User ID]

    WHERE us.[Department]='FORHANDLER' AND C1.[Potential Business Volume]=BV.Code

    ) AS AntalForhandler

    ,(SELECT COUNT(c1.[Potential Business Volume])

    FROM [LF_Drift].[dbo].[Leasing Fyn$Customer] AS C1

    INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$User Setup] AS US

    ON C1.[Salesperson Code] = us.[User ID]

    WHERE us.[Department]='LANDBRUG' AND C1.[Potential Business Volume]=BV.Code

    ) AS AntalLandbrug

    ,(SELECT COUNT(c1.[Potential Business Volume])

    FROM [LF_Drift].[dbo].[Leasing Fyn$Customer] AS C1

    INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$User Setup] AS US

    ON C1.[Salesperson Code] = us.[User ID]

    WHERE us.[Department]='TRANSPORT' AND C1.[Potential Business Volume]=BV.Code

    ) AS AntalTransport

    ,(SELECT COUNT(c1.[Potential Business Volume])

    FROM [LF_Drift].[dbo].[Leasing Fyn$Customer] AS C1

    INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$User Setup] AS US

    ON C1.[Salesperson Code] = us.[User ID]

    WHERE us.[Department]='KREDIT' AND C1.[Potential Business Volume]=BV.Code

    ) AS AntalKredit

    FROM [LF_Drift].[dbo].[Leasing Fyn$Business Volume] AS BV INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$Customer] AS C

    ON BV.[Code] = C.[Potential Business Volume]

    INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$User Setup] AS US

    ON C.[Salesperson Code] = us.[User ID]

    GROUP BY BV.Code, C.[Potential Business Volume]

    ORDER BY BV.Code

    [/font]

    This sql statement gives me this output (comma-separated):

    Code, AntalTotal, AntalForhandler, AntalLandbrug, AntalTransport, AntalKredit

    A + 5 MIO, 10, 9, 8, 7, 6

    B 2 - 5 MIO, 20, 19, 18, 17, 16

    C 0,5 - 2 MIO, 30, 29, 28, 27, 26

    D - 0,5 MIO, 40, 39, 38, 37, 36

    E NEUTRAL, 50, 49, 48, 47, 46

    X UØNSKET, 60, 59, 58, 57, 56

    This sql statement counts how many customers there are in each department in each code (a,b,c,d,e,x).

    This is what I want for , AntalTotal, AntalForhandler, AntalLandbrug, AntalTransport, AntalKredit:

    If a customer has “E NEUTRAL” og nothing (NULL) in field “Potential Business Volume”, it has to check if field “Current Business Volume” is A, B, C or D. If so, it must be counted.

    I hope this help.

  • Let's start with some formatting so we can read this. You can use the IFCode shortcuts over on the left side when posting to include your code in a code box which will maintain the formatting.

    SELECT DISTINCT BV.[Code]

    ,count(C.[Potential Business Volume]) AS AntalTotal

    ,(

    SELECT COUNT(c1.[Potential Business Volume])

    FROM [LF_Drift].[dbo].[Leasing Fyn$Customer] AS C1

    INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$User Setup] AS US ON C1.[Salesperson Code] = us.[User ID]

    WHERE us.[Department] = 'FORHANDLER'

    AND C1.[Potential Business Volume] = BV.Code

    ) AS AntalForhandler

    ,(

    SELECT COUNT(c1.[Potential Business Volume])

    FROM [LF_Drift].[dbo].[Leasing Fyn$Customer] AS C1

    INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$User Setup] AS US ON C1.[Salesperson Code] = us.[User ID]

    WHERE us.[Department] = 'LANDBRUG'

    AND C1.[Potential Business Volume] = BV.Code

    ) AS AntalLandbrug

    ,(

    SELECT COUNT(c1.[Potential Business Volume])

    FROM [LF_Drift].[dbo].[Leasing Fyn$Customer] AS C1

    INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$User Setup] AS US ON C1.[Salesperson Code] = us.[User ID]

    WHERE us.[Department] = 'TRANSPORT'

    AND C1.[Potential Business Volume] = BV.Code

    ) AS AntalTransport

    ,(

    SELECT COUNT(c1.[Potential Business Volume])

    FROM [LF_Drift].[dbo].[Leasing Fyn$Customer] AS C1

    INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$User Setup] AS US ON C1.[Salesperson Code] = us.[User ID]

    WHERE us.[Department] = 'KREDIT'

    AND C1.[Potential Business Volume] = BV.Code

    ) AS AntalKredit

    FROM [LF_Drift].[dbo].[Leasing Fyn$Business Volume] AS BV

    INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$Customer] AS C ON BV.[Code] = C.[Potential Business Volume]

    INNER JOIN [LF_Drift].[dbo].[Leasing Fyn$User Setup] AS US ON C.[Salesperson Code] = us.[User ID]

    GROUP BY BV.Code

    ,C.[Potential Business Volume]

    ORDER BY BV.Code

    So now we can see the query. It would be extremely helpful if you could post ddl (create table statements) and sample data (as inserts) along with the desired output based on your sample data. We can help you figure this out when we have something to work with. Please take a look at the first article referenced in my signature for best practices when posting questions.

    Also, it seems we can greatly improve the performance of this by pulling from the base tables one time instead of over and over for each column.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • So, I hope this is done in the right way.

    This should be the ddl and sample data. I have not made ddl before.

    'Business Volume

    USE [LF_Drift]

    GO

    /****** Object: Table [dbo].[LF$Business Volume] Script Date: 13-11-2014 08:17:49 ******/

    DROP TABLE [dbo].[LF$Business Volume]

    GO

    /****** Object: Table [dbo].[LF$Business Volume] Script Date: 13-11-2014 08:17:49 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[LF$Business Volume](

    [Code] [varchar](20) NOT NULL,

    CONSTRAINT [LF$Business Volume$0] PRIMARY KEY CLUSTERED

    (

    [Code] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [Data Filegroup 1]

    ) ON [Data Filegroup 1]

    GO

    'User Setup

    USE [LF_Drift]

    GO

    /****** Object: Table [dbo].[LF$User Setup] Script Date: 13-11-2014 08:10:52 ******/

    DROP TABLE [dbo].[LF$User Setup]

    GO

    /****** Object: Table [dbo].[LF$User Setup] Script Date: 13-11-2014 08:10:52 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[LF$User Setup](

    [User ID] [varchar](20) NOT NULL,

    [Department] [varchar](10) NOT NULL,

    CONSTRAINT [LF$User Setup$0] PRIMARY KEY CLUSTERED

    (

    [User ID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [Data Filegroup 1]

    ) ON [Data Filegroup 1]

    GO

    SET ANSI_PADDING OFF

    GO

    'Customer

    USE [LF_Drift]

    GO

    /****** Object: Table [dbo].[LF$Customer] Script Date: 13-11-2014 08:18:08 ******/

    DROP TABLE [dbo].[LF$Customer]

    GO

    /****** Object: Table [dbo].[LF$Customer] Script Date: 13-11-2014 08:18:08 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    SET ANSI_PADDING ON

    GO

    CREATE TABLE [dbo].[LF$Customer](

    [No_] [varchar](20) NOT NULL,

    [Salesperson Code] [varchar](10) NOT NULL,

    [Current Business Volume] [varchar](20) NOT NULL,

    [Potential Business Volume] [varchar](20) NOT NULL,

    CONSTRAINT [LF$Customer$0] PRIMARY KEY CLUSTERED

    (

    [No_] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [Data Filegroup 1]

    ) ON [Data Filegroup 1] TEXTIMAGE_ON [Data Filegroup 1]

    GO

    SET ANSI_PADDING OFF

    GO

    'Business Volume

    --===== All Inserts into the IDENTITY column

    SET IDENTITY_INSERT Business Volume ON

    --===== Insert the test data into the test table

    INSERT INTO Business Volume

    (Code)

    SELECT 'A + 5 MIO' UNION ALL

    SELECT 'B 2 - 5 MIO' UNION ALL

    SELECT 'C 0,5 - 2 MIO' UNION ALL

    SELECT 'D - 0,5 MIO' UNION ALL

    SELECT 'E NEUTRAL' UNION ALL

    SELECT 'X UØNSKET'

    --===== Set the identity insert back to normal

    SET IDENTITY_INSERT Business Volume ON

    'User Setup

    --===== All Inserts into the IDENTITY column

    SET IDENTITY_INSERT User Setup ON

    --===== Insert the test data into the test table

    INSERT INTO User Setup

    (User ID, Department)

    SELECT 'JHP','LANDBRUG' UNION ALL

    SELECT 'STE','LANDBRUG' UNION ALL

    SELECT 'TRO','LANDBRUG' UNION ALL

    SELECT 'JQH','LANDBRUG' UNION ALL

    SELECT 'PAS','LANDBRUG' UNION ALL

    SELECT 'MQW','LANDBRUG' UNION ALL

    SELECT 'NEX','TRANSPORT' UNION ALL

    SELECT 'SLO','TRANSPORT' UNION ALL

    SELECT 'LLY','TRANSPORT' UNION ALL

    SELECT 'KAL','TRANSPORT' UNION ALL

    SELECT 'TST','TRANSPORT' UNION ALL

    SELECT 'SER','TRANSPORT' UNION ALL

    SELECT 'LKA','FORHANDLER' UNION ALL

    SELECT 'GEC','FORHANDLER' UNION ALL

    SELECT 'LMO','FORHANDLER' UNION ALL

    SELECT 'TSV','FORHANDLER' UNION ALL

    SELECT 'JPI','KREDIT' UNION ALL

    SELECT 'JRY','KREDIT' UNION ALL

    SELECT 'JVA','KREDIT' UNION ALL

    SELECT 'SSS','KREDIT'

    --===== Set the identity insert back to normal

    SET IDENTITY_INSERT User Setup ON

    'Customer

    --===== All Inserts into the IDENTITY column

    SET IDENTITY_INSERT Customer ON

    --===== Insert the test data into the test table

    INSERT INTO Customer

    (No_, Salesperson Code, Current Business Volume, Potential Business Volume)

    SELECT '209517','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209519','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209658','GEC','B 2 - 5 MIO','E NEUTRAL' UNION ALL

    SELECT '209528','GEC','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209661','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209658','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209529','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209539','GEC','B 2 - 5 MIO','E NEUTRAL' UNION ALL

    SELECT '209523','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209544','LKA','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209542','LKA','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209670','LKA','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209548','LKA','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209657','LKA','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209545','LKA','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209532','LMO','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209540','LMO','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209536','TST','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209543','LLY','C 0,5 - 2 MIO','E NEUTRAL' UNION ALL

    SELECT '209547','LLY','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209651','SER','E NEUTRAL','X UØNSKET' UNION ALL

    SELECT '209516','STE','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209516','STE','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209524','STE','C 0,5 - 2 MIO','E NEUTRAL' UNION ALL

    SELECT '209524','STE','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209659','MQW','E NEUTRAL','D - 0,5 MIO' UNION ALL

    SELECT '209659','MQW','E NEUTRAL','D - 0,5 MIO' UNION ALL

    SELECT '209664','JQH','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209525','JQH','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209664','JQH','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209525','JQH','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209531','JHP','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209546','JHP','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209666','JHP','C 0,5 - 2 MIO','E NEUTRAL' UNION ALL

    SELECT '209531','JHP','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209546','JHP','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209666','JHP','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209531','JPI','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209546','JPI','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209666','JPI','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209531','JPI','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209546','JPI','E NEUTRAL','E NEUTRAL'

    --===== Set the identity insert back to normal

    SET IDENTITY_INSERT Customer ON

  • Your ddl does not work at all. You have a lot of errors in there. You are setting identity insert but none of the tables have an identity column and many other issues. I cleaned this up as best as I could. This will at least generate the tables but you have primary key violations. Can you clean this up and test it on a test database so it will create your test data? Also, I would highly recommend not using prefixes (LF), special characters ($) or spaces in object names. It really makes it painful to work with.

    /*

    drop table [LF$Business Volume]

    drop table [LF$User Setup]

    drop table [LF$Customer]

    */

    CREATE TABLE [dbo].[LF$Business Volume](

    [Code] [varchar](20) NOT NULL,

    CONSTRAINT [LF$Business Volume$0] PRIMARY KEY CLUSTERED

    (

    [Code] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

    )

    GO

    CREATE TABLE [dbo].[LF$User Setup](

    [User ID] [varchar](20) NOT NULL,

    [Department] [varchar](10) NOT NULL,

    CONSTRAINT [LF$User Setup$0] PRIMARY KEY CLUSTERED

    (

    [User ID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)

    )

    GO

    CREATE TABLE [dbo].[LF$Customer](

    [No_] [varchar](20) NOT NULL,

    [Salesperson Code] [varchar](10) NOT NULL,

    [Current Business Volume] [varchar](20) NOT NULL,

    [Potential Business Volume] [varchar](20) NOT NULL,

    CONSTRAINT [LF$Customer$0] PRIMARY KEY CLUSTERED

    (

    [No_] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100)

    )

    GO

    --===== Insert the test data into the test table

    INSERT INTO [LF$Business Volume]

    (Code)

    SELECT 'A + 5 MIO' UNION ALL

    SELECT 'B 2 - 5 MIO' UNION ALL

    SELECT 'C 0,5 - 2 MIO' UNION ALL

    SELECT 'D - 0,5 MIO' UNION ALL

    SELECT 'E NEUTRAL' UNION ALL

    SELECT 'X UØNSKET'

    --===== Insert the test data into the test table

    INSERT INTO [LF$User Setup]

    ([User ID], Department)

    SELECT 'JHP','LANDBRUG' UNION ALL

    SELECT 'STE','LANDBRUG' UNION ALL

    SELECT 'TRO','LANDBRUG' UNION ALL

    SELECT 'JQH','LANDBRUG' UNION ALL

    SELECT 'PAS','LANDBRUG' UNION ALL

    SELECT 'MQW','LANDBRUG' UNION ALL

    SELECT 'NEX','TRANSPORT' UNION ALL

    SELECT 'SLO','TRANSPORT' UNION ALL

    SELECT 'LLY','TRANSPORT' UNION ALL

    SELECT 'KAL','TRANSPORT' UNION ALL

    SELECT 'TST','TRANSPORT' UNION ALL

    SELECT 'SER','TRANSPORT' UNION ALL

    SELECT 'LKA','FORHANDLER' UNION ALL

    SELECT 'GEC','FORHANDLER' UNION ALL

    SELECT 'LMO','FORHANDLER' UNION ALL

    SELECT 'TSV','FORHANDLER' UNION ALL

    SELECT 'JPI','KREDIT' UNION ALL

    SELECT 'JRY','KREDIT' UNION ALL

    SELECT 'JVA','KREDIT' UNION ALL

    SELECT 'SSS','KREDIT'

    --===== Insert the test data into the test table

    INSERT INTO [LF$Customer]

    (No_, [Salesperson Code], [Current Business Volume], [Potential Business Volume])

    SELECT '209517','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209519','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209658','GEC','B 2 - 5 MIO','E NEUTRAL' UNION ALL

    SELECT '209528','GEC','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209661','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209658','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209529','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209539','GEC','B 2 - 5 MIO','E NEUTRAL' UNION ALL

    SELECT '209523','GEC','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209544','LKA','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209542','LKA','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209670','LKA','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209548','LKA','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209657','LKA','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209545','LKA','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209532','LMO','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209540','LMO','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209536','TST','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209543','LLY','C 0,5 - 2 MIO','E NEUTRAL' UNION ALL

    SELECT '209547','LLY','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209651','SER','E NEUTRAL','X UØNSKET' UNION ALL

    SELECT '209516','STE','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209516','STE','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209524','STE','C 0,5 - 2 MIO','E NEUTRAL' UNION ALL

    SELECT '209524','STE','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209659','MQW','E NEUTRAL','D - 0,5 MIO' UNION ALL

    SELECT '209659','MQW','E NEUTRAL','D - 0,5 MIO' UNION ALL

    SELECT '209664','JQH','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209525','JQH','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209664','JQH','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209525','JQH','D - 0,5 MIO','E NEUTRAL' UNION ALL

    SELECT '209531','JHP','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209546','JHP','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209666','JHP','C 0,5 - 2 MIO','E NEUTRAL' UNION ALL

    SELECT '209531','JHP','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209546','JHP','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209666','JHP','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209531','JPI','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209546','JPI','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209666','JPI','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209531','JPI','E NEUTRAL','E NEUTRAL' UNION ALL

    SELECT '209546','JPI','E NEUTRAL','E NEUTRAL'

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply