0

I have "duration" Field in SQL table with type "Bigint", inside SQL procedure, we convert it into decimal when we divide it by 3600 , Now when we get Datatable in c# with this Store procedure, we get this duration field with datatype decimal .

Now we have one another field "Price" in SQL table with type "Money" and this field get converted into "decimal" type by .net when we get datatable from store procedure means "SQL money type is equivalent to .net decimal type " .

Now inside code, we have some logic which works on bases of datatype of table fields, So we need to run this logic for only "Money" type fields, Now I got stuck at this point, how can I distinguish b/w these "duration" and "Price" field because in C# datatable they both are in "Decimal" datatype .

Now according me whether I need to change the conversion of duration by decimal to float in store procedure or something else, Please suggest me .

Manoj S Pant
  • 85
  • 2
  • 12
  • 1
    [Just use decimal for both](https://sqlblog.org/search/SearchResults.aspx?q=data+type+money+decimal&s=18). What do you get from using the money data type, other than loss of precision and less flexibility? What kind of logic does your code expect to do differently if something is money? Are you just talking about displaying a dollar sign or something? And you want that to happen based on the SQL Server data type instead of actual tangible data point? – Aaron Bertrand Sep 17 '14 at 18:11
  • Aaron : Thanks for your reply, yes I want to show the symbols of different currency, so that's why, I need to distinguish these two type, – Manoj S Pant Sep 17 '14 at 20:21

1 Answers1

3

Change the code that looks at data types to look at column names instead.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • codeCaseter : Thanks for reply, but it is generalize code which work with different tables . – Manoj S Pant Sep 17 '14 at 20:19
  • 2
    If in your code is specified _"all decimal type variables will be divided by 3600"_ or whatever, which is now claimed untrue, then that code is broken. You need to change that code. Without seeing that or the rest of the relevant code, nobody can properly answer this question. – CodeCaster Sep 17 '14 at 20:22