March 29, 2013 at 5:51 pm
Hello,
I was going to create a computed column based of course upon the values in three other columns. Of the four (the fourth being the computed column) involved 3 are defined as time(7). The fourth is tinyint. The formula is quite simple. (A*B)+C = Answer.
So
ColumnA time(7)
ColumnB tinyint
ColumnC time(7)
ColumnAnswer time(7)
My formula is like this:
(([ColumnA] * [ColumnB]) + [ColumnC])
The error...time is incompatible with tinyint.
So am I going to have to move this to a udf and even then not sure what I would CAST / CONVERT to accomplish the multiplication??
Pointers would be greatly appreciated
JB
So to add to this I have written the following in SSMS:
DECLARE @a time(0)
DECLARE @b-2 tinyint
DECLARE @C time(0)
SET @a = 0:1:30'
--Well this won't do because I need everything in seconds to do the math sooo...
DECLARE @Aseconds int
SET @Aseconds = (DATEPART(HOUR, @a) * 3600) + (DATEPART(MINUTE, @a) * 60) + (DATEPART(SECOND, @a))
SELECT @Aseconds * @b-2
--then convert it back to time to add @C
SELECT CONVERT(varchar, DATEADD(ms, @Aseconds * 1000, 0), 114)
--Now dateadd each part really?? should I do this in .NET instead?
March 29, 2013 at 6:06 pm
Give us a clue what you are trying to achieve, because multiplying a time doesn't make sense.
MM
select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);
March 29, 2013 at 6:08 pm
Well I am trying to figure out how long it should take to do something. So say the instructor says I am giving you 5 minutes to find each hidden item and there are three hidden items. Well then the person has 15 minutes to find all three.
March 29, 2013 at 6:20 pm
In this case, I would not use the time data type. Plus, if you do and the total time reaches 24 hours or more, the time data type will fail there as well. Find a common base unit, use it and the integer data type.
March 29, 2013 at 6:30 pm
That's basically what I'm going to do. Just keep them as int in SQL and let .NET timespan do the heavy lifting.....I just thought Msoft...you know the guys who gave us TimeSpan might have thought to add this capability to MSSQL??
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply