Data conversion error when using floor function in sql - sql

please help me on this.
i am trying to check if .two decimal value not in a column using this.
FLOOR(LOG10(REVERSE(ABS(M.Description_12_Value)+1)))+1 <> 2
but i am getting error
Conversion failed when converting the varchar value '8.5' to data
type int.
Thanks

One of the columns you are comparing, either Description_2_Value/Description_3_Value/Description_10_Value is returning that 8.5 value and hence the query is throwing the error while comparing '8.5' > something. You need to cast the value RHS value in your condition to a varchar to fix it. See working example below:
if ('2.5' > '2')
begin
print 'success'
end

Related

Update value in Teradata with different datatype Error 3754

I'm trying to update a column value on Teradata , the source column are a varchar and the target a decimal (COD_ARTMDL to NUM_ARTAPP)
I tried to do a SET NUM_ARTAPP = TO_NUMBER(COD_ARTMDL)
But have an error :
UPDATE Failed. 3754: Precision error in FLOAT type constant or during implicit conversions.
Can you help me with this ?
Thanks

Search with inequalities on string property

We are using NHibernate over SQL Server and SQLite.
The database stores records in rows rather than columns -- each row having Path|Value as columns. Path and Value are both string properties.
For certain values of Path we would like to query for inequalities -- greater-than, less-than, etc.
The trouble we are having is that because the properties are strings, the inequalities are using string comparisons -- for example, searching for Value >= 18 returns rows where Value = 5. Unfortunately we are having trouble working around this.
1) This restriction produces incorrect results (saying 18 < 5):
Restrictions.Ge("Value", item.Value);
2) We tried casting the value to an integer, but this code produces a SqlException from NHibernate -- Error converting data type nvarchar to bigint.
Restrictions.Le(Projections.Cast(NHibernateUtil.Int64, Projections.Property("SearchString")), item.Value)
3) We were looking for a way to pad the property value with zeros (so that we would get 018 > 005), but could not find a way to do this in NHibernate.
Does anyone have any advice?
Thank you in advance!
Assuming that you want to compare on integer value, with IQueryOver:
1) This restriction produces incorrect results (saying 18 < 5):
Restrictions.Ge("Value", item.Value);
Restrictions.Ge
(
Projections.Cast(NHibernateUtil.Int32, Projections.Property<YourEntity>(x => x.YourProperty))
, intValue
)
Convert your datatype accordingly. If your C# datatype (intValue) is already numeric, no need to convert it. If your x.YourProperty is already numeric type, no need to convert it. Adjust above code accordingly.
2) We tried casting the value to an integer, but this code produces a SqlException from NHibernate -- Error converting data type nvarchar to bigint.
Restrictions.Le(Projections.Cast(NHibernateUtil.Int64, Projections.Property("SearchString")), item.Value)
Refer the above and check the datatype of item.Value.

Conversion failed when converting the varchar value '095-10197-10' to data type int. Error

If I use simple select * FROM View, I am getting the proper output but when i try to filtered out the rows using where condition with specific columns (e.g: SELECT * FROM VIEW where Amount = '1.85', then I am getting an error like
Conversion failed when converting the varchar value '095-10197-10' to
data type int.
IF I check '095-10197-10' VALUE , there is not such value in any column coming through View.
Any idea what causing the issue.

SQL Server : conversion error numeric to varchar case

I have this query:
CASE ClaimsFees.TBA
WHEN 0 THEN CAST(IndemnityReserve AS NUMERIC(9,2))
ELSE 'TBA'
END AS 'Reserve Indemnity'
but I always get this error:
Error converting data type varchar to numeric
I have tried to convert TBA as numeric but I can't do this, I also can't convert all the results to varchar because when I transfer to Excel file the number 1.325,27 becomes 132.527,00 with the ##,##0.00 format.
Is there a method in SQL Server that I can use to solve this?
The column can only have one type, and as 'TBA' can only be a string, you'll need to make the numeric a string too.
CASE ClaimsFees.TBA WHEN 0
then cast(cast(IndemnityReserve as NUMERIC(9,2)) as varchar(12))
else 'TBA'
end as 'Reserve Indemnity',

Conversion failed when converting the varchar value 'Yes' to data type bit

I used a case to change boolean column values to a text string that actually means something. Firstly, when doing a WHERE statement on these columns do I use the boolean values or the updated text strings?
I used:
WHERE TrainingProgram.blnInCatalogue = 'Yes'
AND TrainingProgram.blnActive = 'Inactive'
But I get the error:
Conversion failed when converting the varchar value 'Yes' to data type bit.
Am I doing something wrong?
For true, try using:
WHERE TrainingProgram.blnInCatalogue <> 0
For false, try using:
WHERE TrainingProgram.blnInCatalogue = 0
The blnInCatalogue column is a bit field, and it doesn't understand what the string 'Yes' means. It only knows 0 or 1.
Though you can use a case to display bit columns as readable strings, their internal value is still bit. They can only be compared to 0 or 1.