DECLARE @Category VARCHAR (3)
SET @Category='001'
SELECT CASE WHEN Category=@Category
THEN CONCAT(TotalCommission , '*disc')
ELSE CONCAT(TotalCommission , '') END AS TotalCommission
FROM GenReport
How Do I Convert VARCHAR to NUMERIC
abiodunajai
396
Reputation points
Please your assistance is needed on the query below.
CREATE TABLE GenReport(
Category varchar (3) NULL,
TotalCommission Decimal (19,4) NULL,
EarnedCommission Decimal (19,4) null
)
INSERT INTO GenReport (Category, TotalCommission, EarnedCommission)
VALUES ('001', 3600.0000, 3600.0000 );
INSERT INTO GenReport (Category, TotalCommission, EarnedCommission)
VALUES ('001', 564827.1800, 564827.1800 );
INSERT INTO GenReport (Category, TotalCommission, EarnedCommission)
VALUES ('001', 2700.0000, 2700.0000 );
INSERT INTO GenReport (Category, TotalCommission, EarnedCommission)
VALUES ('001', 4700.0000, 4700.0000 );
INSERT INTO GenReport (Category, TotalCommission, EarnedCommission)
VALUES ('001', 6800.0000, 6800.0000 );
DECLARE @Category VARCHAR (3)
SET @Category='001'
SELECT CASE WHEN Category=@Category
THEN CONCAT(TotalCommission , '*disc')
ELSE TotalCommission END AS TotalCommission
FROM GenReport
My TotalCommission output result should look like below.
The error message is stated below
Msg 8114, Level 16, State 5, Line 110
Error converting data type varchar to numeric.
Thank you for your anticipated quick response.
Best regards,
Abiodunajai
Azure SQL Database
Azure SQL Database
An Azure relational database service.
6,326 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,061 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,702 questions
SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,344 questions
SQL Server Other
14,494 questions
Accepted answer
-
Jingyang Li 5,896 Reputation points Volunteer Moderator
2023-02-24T17:38:17.01+00:00
1 additional answer
Sort by: Most helpful
-
Naomi Nosonovsky 8,431 Reputation points
2023-02-24T17:29:17.2233333+00:00 Try the following:
DECLARE @Category VARCHAR (3) SET @Category='001' SELECT CASE WHEN Category=@Category THEN CONCAT(TotalCommission , '*disc') ELSE CAST(TotalCommission AS VARCHAR(15)) END AS TotalCommission FROM GenReport