Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Sql query help

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2014-02-11 : 21:25:25
Hi friends,

I have a table with the following fields
CustomerType Customer_Score
Daily 1
Regular 0
Weekly 3

What i basically want to do is that i want to select the data from the above table and show the result in the following way

CustomerType Absent Weak Strong Moderate
Daily 1
Regular 0
Weekly 3


how i determine is that i already have a predefined rule
the daly customer has folowing rule 0-absent 1-weak 2-strong 2.5-Moderate
weekly customer has the follwoing rule 0-absent 1-weak 2-strng 3-Moderate

Hope my question is clear..For each customertype there is a predefined numeric to determine the frequencytype and i wnat to split them in that colums.

Thank you

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-12 : 00:27:25
[code]
SELECT CustomerType,
CASE Customer_Score
WHEN 0
THEN Customer_Score
END AS Absent,
CASE Customer_Score
WHEN 1
THEN Customer_Score
END AS Weak,
CASE Customer_Score
WHEN 2
THEN Customer_Score
END AS Strong,
CASE
WHEN ((Customer_Score = 2.5 AND CustomerType = 'Daily')
OR (Customer_Score = 3 AND CustomerType = 'Weekly'))
THEN Customer_Score
END AS Moderate
FROM Table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2014-02-12 : 11:14:41
Thank you visakh16 that got me started.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-13 : 08:09:29
cool

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -