Click here to Skip to main content
15,898,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

Thanks for attention.

Can I convert a row into a string/nvarchar variable.

like:

id name loc joindate active
1 AB KOL 2012-03-22 true


I want to this
like
1#AB#KOL#2012-03-22@true.

please help.

Thanks in Advance.
Posted

Hi Saha...

Please try the below query.
SQL
select top 1 [name]+' #'+[product]+' #'+CONVERT(varchar,[amount],0)+'@'+convert(varchar,[sales ID]) 
 from sales 


It will help you.
 
Share this answer
 
v2
Comments
StianSandberg 19-Jul-12 7:52am    
simple but still the perfect solution!
Tejas Vaishnav 19-Jul-12 8:33am    
Perfect...
Nice My 5+
Kaushik Saha from Kolkata,India 19-Jul-12 8:35am    
Thanks for answer.your solution is effective but a limitation if a value is null then have some problem arise.
Arul R Ece 20-Jul-12 0:44am    
Hi....

Please try this.

select top 1 [name]+' #'+[product]+' #'+CONVERT(varchar,[amount],0)+'@'+
case when isnull([sales ID],'')='' then 'Null'
else convert(varchar,[sales ID])
end
from sales
try this

SQL
SELECT TOP 1 
    CONVERT(varchar(MAX),id) +'#'+ name + '#' + loc + '#' +  
    CONVERT(varchar(MAX),getdate())
    + '@' + CASE WHEN active = 1 THEN 'true' ELSE 'false' END
FROM dbo.Yourtable
 
Share this answer
 
C#
select Top 1 
COALESCE(CONVERT(VARCHAR,datetest.ID),'blank')+'#'+
COALESCE(Name,'blank')+'#'+
COALESCE(loc,'blank')+'#'+
COALESCE(convert(varchar,joindate),'blank')+'#'+
COALESCE(case when convert(varchar,active)=1 then 'true' else 'false' end,'blank')
 from tbl_emp



This is working perfectly
 
Share this 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