Home > OS >  Store duration of song in SQL Server
Store duration of song in SQL Server

Time:07-21

I'm going to store the Length of songs in my table and I chose the data type as decimal(2,2), but I got error. I search for this question alot but couldnt solve it. Can any one tell me that which data type should I use and how exactly must write it in query?

enter image description here

CodePudding user response:

I'm not sure decimal is the right way to store time, as the info after the decimal point isn't 100 based.

Could you store the duration as an integer? In seconds?

Writing: 3m:30s -> 3*60 30 = 210 seconds

Reading: 210 seconds/60 seconds` (3 30)

CodePudding user response:

Your decimal specification is incorrect. decimal(2,2) says you have 2 numbers, 2 of which come after the decimal. Try decimal(3,2) and that should fix your error, but you might need to play with the precision and scale as you work further.

More information: https://docs.microsoft.com/en-us/sql/t-sql/data-types/decimal-and-numeric-transact-sql

decimal[ (p[ ,s] )] and numeric[ (p[ ,s] )]

p (precision) The maximum total number of decimal digits to be stored. This number includes both the left and the right sides of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.

s (scale) The number of decimal digits that are stored to the right of the decimal point. This number is subtracted from p to determine the maximum number of digits to the left of the decimal point. Scale must be a value from 0 through p, and can only be specified if precision is specified. The default scale is 0 and so 0 <= s <= p. Maximum storage sizes vary, based on the precision.

  • Related