Click here to Skip to main content
15,569,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir i have a Sql Query:-


SQL
select  [1] as  Jan,[2] as  Feb
from StudentDiscountItem
pivot (
sum (conP) for mnameid in ([1],[2])) as t
where studentid=3575 And Sessionid='20152016'



Output of Query is :-

Jan -- Feb

20 -- 10

i need to add % sign with 10 and 20 like 10%,20%.

How can i do it.
Posted

Not sure but I think one or both of the following two queries should do your job
SQL
select  (cast([1] as varchar)+'%') as  Jan,cast([2] as varchar)+'%') as  Feb
from StudentDiscountItem
pivot (
sum (conP) for mnameid in ([1],[2])) as t
where studentid=3575 And Sessionid='20152016';

If the above doesn't work, then try this
SQL
select cast(Jan as varchar)+'%' as Jan, cast(Feb as varchar)+'%' as Feb
from (
select  [1] as  Jan,[2] as  Feb
from StudentDiscountItem
pivot (
sum (conP) for mnameid in ([1],[2])) as t
where studentid=3575 And Sessionid='20152016';
) as t

Hope, it helps :)
 
Share this answer
 
Comments
TCS54321 9-Apr-15 2:32am    
Its Working.. tnx
TCS54321 9-Apr-15 2:33am    
boths are working
Suvendu Shekhar Giri 9-Apr-15 2:44am    
Glad that it helped :)
Try:
SQL
SELECT CONVERT(VARCHAR(50), [1]) + '%' as  Jan...

or (MS SQL Server 2012 and up):
SQL
SELECT CONCAT([1], '%') as  Jan...


[EDIT]
SQL
SELECT CONVERT(VARCHAR(50), [Jan]) + '%' as  Jan...
FROM (
    -- your pivot: SELECT [1] AS Jan...
) AS T

Use the same logic for CONCAT.
 
Share this answer
 
v3
Comments
TCS54321 9-Apr-15 2:28am    
No one working
TCS54321 9-Apr-15 2:30am    
1)Error converting data type varchar to float
2)'CONCAT' is not a recognized built-in function name
This is the errors
Maciej Los 9-Apr-15 2:32am    
See updated answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900