[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1069
  • Last Modified:

Concatenate 2 columns in sql server

I have two columns which i want to concatenate using sql query and later willl be using this query in vb.net to display two columns.

Select isnull(a, '') + '' +  isnull(b, '') from table 1

this displays the sum of these two columns in the result
However i want to display the columns as a X b and that should  be one column using code in vb.net.

0
passion420
Asked:
passion420
  • 4
  • 3
1 Solution
 
chapmandewCommented:
>>However i want to display the columns as a X b and that should  be one column using code in vb.net.

I don't know what you mean.
0
 
udaya kumar laligondlaTechnical LeadCommented:
I think you want this
Select isnull(a, '') + ' X ' +  isnull(b, '') from table1
0
 
passion420Author Commented:
the above query is giving me some of two columns a+b i need to display these columns as aXb where X is just a letter and that should be displayed as one column as aXb in the query.

Also i will be using this query in my vb.net code later on so was just wondering if someone can provide me the equivalent code in vb.net that will be really helpful.

Thanks !!
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
passion420Author Commented:
sorry that is sum*  not some in the above comment
0
 
udaya kumar laligondlaTechnical LeadCommented:
can you execute and try in sql server management studio
Select isnull(a, '') + ' X ' +  isnull(b, '') from table1
will actually display value in B X value in B  not the sum.
if you are looking for different output give some sample data
0
 
passion420Author Commented:
I am getting this error when executed the above said query:

Error converting data type varchar to float........i think need to convert second field?? how to write that...thanks !!
0
 
udaya kumar laligondlaTechnical LeadCommented:
Select convert(varchar,isnull(a, '')) + ' X ' +  convert(varchar,isnull(b, '')) from table1
0
 
passion420Author Commented:
Hi

How can i include space b/w them??

like a  x  b ?? in the above query........??
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now