Before, when I was doing statistics, I needed a field to show the order quantity and order amount for a month, and to combine it into a single field in parentheses.
The result of the statistic is probably this, first we create some simulation data
---create order form---CREATE TABLE Omsorder (UidintIdentity1,1) primary key, Organizename varchar ( -) notNULL, OrderCountintNotNULL, OrdermoneyfloatNotNULL)--Add analog data---INSERT INTO Omsorder (Organizename,ordercount,ordermoney) VALUES ('Sync Clinic', -,54231),('Mercy Clinic', About,12123),('Longhua Clinic', the,35212)
This is the result of the statistics, but we need the order quantity (order Amount) to display this way
The composition syntax is converted with the cast () function, with the following syntax
-- Combination Syntax--- Select (Castasvarchar('+ '+ Cast as varchar ()) + ' )') from tableName
1. Use parentheses to combine two fields into one and display
--1. Use () to combine two fields--SelectA.organizename, (CAST(OrderCount as varchar( -))+'('+CAST(Ordermoney as varchar( -))+'yuan)') asOrderData fromOmsorder asA
When combined, the returned data is as follows:
2. Use---number to implement two fields combined into one field
--2, with--two field combinations--SelectA.organizename, (CAST(OrderCount as varchar( -))+'--'+CAST(Ordermoney as varchar( -))+'Yuan') asOrderData fromOmsorder asA
When combined, the returned data is as follows:
Ps:
1) The data type of the conversion field is converted directly to the varchar () type, whether int, float, varchar, etc.
2) The cast () function is converted and concatenated with the "+" sign, and the whole as a whole is returned as a field in parentheses.
How to combine two field data into one field display in SQL Server (field and field add special symbols)