Showing posts with label integer. Show all posts
Showing posts with label integer. Show all posts

Thursday, March 22, 2012

Adding two dates

I have two fields, Date Purchased (smalldatetime) and warranty in months (integer).

can anyone help me to formulate a query to show the date when the warranty ends, and/or the remaining days/months in the warranty please?

I'm not sure if its doable, but i would really appreciate it if anyone can help me!

Give a look to the DATEADD function in books online; it looks like this:

declare @.example table
( rid integer,
datePurchased smalldatetime,
warranty integer
)

insert into @.example
select 1, '4/8/7', 3 union all
select 2, '5/14/7', 12

select rid,
convert(varchar(10), datePurchased, 101) as datePurchased,
warranty,
dateadd (mm, warranty, datePurchased) as warrantyEndDate,
datediff (day, getdate(), dateadd (mm, warranty, datePurchased)) as daysRemaining,
datediff (mm, getdate(), dateadd (mm, warranty, datePurchased)) as monthsRemaining
from @.example

/*
rid datePurchased warranty warrantyEndDate daysRemaining monthsRemaining
-- - -- - -
1 04/08/2007 3 2007-07-08 00:00:00 45 2
2 05/14/2007 12 2008-05-14 00:00:00 356 12
*/

Thursday, February 16, 2012

adding commas into integer

while selecting the field, I want it to be display with commas.
for example,
10000 become 10,000
without decimal placed at the end.
I have tried using smallmoney format but there is decimal places.Take a look at DECIMAL datatype
"dapdap" <dapdap@.discussions.microsoft.com> wrote in message
news:22FBBC46-4B9D-4377-A806-D4D79EE81013@.microsoft.com...
> while selecting the field, I want it to be display with commas.
> for example,
> 10000 become 10,000
> without decimal placed at the end.
> I have tried using smallmoney format but there is decimal places.|||Formatting is controlled by your client application, not by SQL Server. Ask
this question in a forum for the app or programming language you are using.
Certainly you could get SQL to return a string instead of a number but why
would you want to do that with the obvious divantages for performance,
complexity and special handling at the client?
David Portas
SQL Server MVP
--
"dapdap" wrote:

> while selecting the field, I want it to be display with commas.
> for example,
> 10000 become 10,000
> without decimal placed at the end.
> I have tried using smallmoney format but there is decimal places.|||>> selecting the field, I want it to be display with commas. <<
Let's get back to the basics of an RDBMS. Rows are not records; fields
are not columns; tables are not files. In a tiered architecture, the
display formatting is done in the front end and never in the database.
A good SQL programmer avoids proprietary datatypes.