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
 General SQL Server Forums
 New to SQL Server Programming
 CREATE VIEW and change data type

Author  Topic 

rizo
Starting Member

16 Posts

Posted - 2012-08-03 : 10:08:12
Below is the sample code.
How can I create a view and set PriceType as a varchar?

CREATE VIEW VoteCount AS

SELECT VoteCount_Base.fi_answerID AS Bank_ID, Count(VoteCount_Base.fi_Session_id) AS AbsoluteVoteCount,
case when Count([fi_Session_id]) > 6
then Count([fi_session_id])
else '<7' end AS PriceType,
Cast ([PriceType] , AS NVARCHAR(50)

FROM VoteCount_Base
GROUP BY VoteCount_Base.fi_answerID;

rizo

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-03 : 10:12:45
Cast the number to VARCHAR as in:
CREATE VIEW VoteCount AS

SELECT
VoteCount_Base.fi_answerID AS Bank_ID,
COUNT(VoteCount_Base.fi_Session_id) AS AbsoluteVoteCount,
CASE
WHEN COUNT([fi_Session_id]) > 6 THEN CAST(COUNT([fi_session_id]) AS VARCHAR(32))
ELSE '<7'
END AS PriceType
FROM
VoteCount_Base
GROUP BY
VoteCount_Base.fi_answerID;
Go to Top of Page

rizo
Starting Member

16 Posts

Posted - 2012-08-03 : 10:16:37
LOVELY STUFF MATE. WORKED A TREAT. THANKS

rizo
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-03 : 12:15:59
A treat to hear that! Glad to be of help!!
Go to Top of Page
   

- Advertisement -