question

Knightgamer avatar image
Knightgamer asked

Urgent help Require

/* ---------------- */


declare @AMT int; set @AMT = 5000

/* -------------------- */


select ApplicationID,

AMT FROM [[DH].[twh].[Responses]

where amt = (select convert(int,sum(Overdue_amt)) from [DH].[twh].[Responses])

Output

Msg 8117, Level 16, State 1, Line 8

Operand data type nvarchar is invalid for sum operator.

group-bysub-querysumnvarcharcast-convert
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
anthony.green avatar image
anthony.green answered

You cannot SUM an NVARCHAR column.
You need to convert Overdue_amt to a numerical type first, before summing, but watch out for any alpha characters in the column as those won't convert


select sum(try_convert(int,Overdue_amt)) from [DH].[twh].[Responses]
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.