David
David

Reputation: 264

Error converting data type varchar to numeric in select statement

Table structure:

(code VARCHAR(5),
description VARCHAR(150),
tax_rate DECIMAL(5,2),)


SELECT t1.code AS code, t1.code AS value, t1.code AS description,
       t1.code + (' + tax_rate + '%)' AS content
 FROM pbostaxinfo t1

The 'tax_rate' prompt the error converting data type varchar to numeric.

I want the result to show eg: AJP (6%).

AJP is the code, and 6 is tax_rate.

Upvotes: 2

Views: 320

Answers (2)

David
David

Reputation: 264

SELECT t1.code AS code, t1.code AS value, t1.code AS description, t1.code + ' (' + CAST(t1.tax_rate AS VARCHAR(5)) + '%)' AS content
FROM pbostaxinfo t1

This is the answer for what i was looking for.

Upvotes: 2

Akhil Job
Akhil Job

Reputation: 419

  SELECT t1.code AS code,
  t1.code      AS value,
  t1.code      AS description,
  t1.code
  ||'('
  ||tax_rate
  ||'%)' AS content
  FROM pbostaxinfo t1 

Upvotes: 1

Related Questions