?
Solved

SQL to Split 1 Record into 2

Posted on 2006-03-30
3
Medium Priority
?
361 Views
Last Modified: 2008-03-10
Hi Guys,

Here is an example:
ID_NUMBER---STREET_DATE---NORMAL_PRICE---BASE_PRICE
001------------01/01/2006-------10.00--------------8.00

The output should be somewhat like this:
ID_NUMBER---STREET_DATE---CONDITION---RATE
001------------01/01/2006-------SRP--------10.00
001------------01/01/2006-------BSE--------8.00

The 3rd column CONDITION is contanst based on the Normal and Base Price.

I would appreciate any help.
Thanks.
0
Comment
Question by:asimahmed073100
  • 2
3 Comments
 
LVL 14

Expert Comment

by:adwiseman
ID: 16336615
Select ID_NUMBER, STREET_DATE, 'SRP' AS Condition, Normal_Price as Rate
FROM MyTable
UNION ALL
Select ID_NUMBER, STREET_DATE, 'SRP' AS Condition, Base_Price as Rate
FROM MyTable
order by ID_NUMBER, Condition
0
 
LVL 14

Assisted Solution

by:adwiseman
adwiseman earned 180 total points
ID: 16336625
sorry, second recordset needed to be BSE

Select ID_NUMBER, STREET_DATE, 'SRP' AS Condition, Normal_Price as Rate
FROM MyTable
UNION ALL
Select ID_NUMBER, STREET_DATE, 'BSE' AS Condition, Base_Price as Rate
FROM MyTable
order by ID_NUMBER, Condition
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 195 total points
ID: 16336665
Or, to avoid two passes thru the main table:


SELECT id_number, street_date,
    type_of_price,
    CASE WHEN type_of_price = 'SRP' THEN normal_price ELSE base_price END
FROM tableName
CROSS JOIN (
    SELECT 'SRP' AS type_of_price
    UNION ALL
    SELECT 'BSE'
) AS types_of_price
ORDER BY id_number, condition DESC
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question