Definitions
[Rec_Num] [int] IDENTITY(1,1) NOT NULL,
[Pro_PCT] [nvarchar](50) NULL
[Max_Off] [nvarchar](50) NULL
[IsExceeds] AS (CONVERT([int],[Pro_PCT])-CONVERT([int],replace([Max_Off],'%','')))
Data
Query
select top 200 * from dbo.FO_Entry
where isexceeds>0
order by Rec_Num desc
The above query works fine and shows the data. But when I change the top 200 to 201 then it throws the below error.
If I run the Top 201 statement 2 or three times then it shows the data. Again if I change the Top 201 to To 202 then again the error popsup.
Any suggestion will be very much helpful.
Note:- Problem occurs when I use where IsExceeds>0 condition. Also I believe that the IsExceeds calculation may be causing this issue.
The real problem is your design, fix that, and the problem goes away. Your column
Pro_PCT
is clearly anint
, and your columnMax_off
is clearly meant to be adecimal
; as it is a percentage.We'll fix
Pro_Pct
first. Firstly check if any values are "bad" (which I don't doubt there will be because you're storing numerical data as anvarchar
):That will give you a dataset back of all the bad data. You'll need to fix all of those values.
After that, you can
ALTER
the table:Now the percentage. First we need to remove all the percent (
'%'
) characters and turn the value into adecimal
. Again, let's get the bad data:Again, fix all your values where it couldn't be converted. Then you can
UPDATE
the value and thenALTER
the table:Now your data is fixed, you should have an easier time implementing the logic for
IsExcess
.