type conversion

patrick

Well-known member
Joined
Dec 5, 2021
Messages
251
Programming Experience
1-3
C#:
declare @calctype int = 5
select @calctype = option from table_1 where optionvar = 'type'

Is your grammar correct?
===>

            (case when (select CAST(option AS int) from table_1 where optionvar = 'type') = 1 then
                abs(round(dm.value, (select CAST(option AS int) from table_1 where optionvar= 'rawdlen'  ) ))
            else
                round(dm.value, (select CAST(option AS int) from table_1 where optionvar = 'rawdlen' ) ) end)

How do I change it ( initial value =5) ? (declare @calctype int = 5)



How do I change it ( initial value =5) ? (declare @calctype int = 5)
 
Last edited:
An error occurs in the code below. Please check this code.

C#:
    declare @rawdlen int = 3
select @rawdlen = optionvalue from table_1 where optionvar = 'rawdlen'
    declare @type int = 0
select @type = optionvalue from table_1 where optionvar = 'avgcalctype'
***In some cases, the ***value of optionvalue column *** is null**. So **I declared ***it as declare @rawdlen int = 3 & declare @type int = 0****
===> How do I change it..
select ...........
(case when @type = 1 then abs(round(dm.value, @rawdlen)) else round(dm.value, @rawdlen) end)
===> ***************
I migrated to the code below. This is the final code that migrated the above code.
select ............
 (case when (select @type = optionvalue from table_1 where optionvar = 'avgcalctype') = 1 then
            abs(round(dm.value, (select @rawddlen = optionvalue from table_1 where optionvar = 'rawdlen')))
      else
            round(dm.value, (select @rawddlen = optionvalue from table_1 where optionvar = 'rawdlen'))
end)
 
Last edited:
That is the oddest looking C# code I have ever seen...
 
Ah, and this is primarily a C# forum...
 
I am far from a SQL expert. I probably know just enough to be dangerous and make DBAs all over the world cringe. So take the following with a huge grain of salt.

As far as I know, the column list in a SELECT statement can use an expression that uses the = operator, but that symbol is treated as an assignment operator, not as a comparison operator. It looks like you are trying to use it as a comparison operator in your SQL statements above. If you need to do the comparisons, but also need the column to appear in the results, then put the column name in the column list, and then do the column value comparison in the WHERE clause.
 

Latest posts

Back
Top Bottom