Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Assign Value to Var via qry result

Author  Topic 

ismailc
Constraint Violating Yak Guru

290 Posts

Posted - 2008-12-24 : 03:56:46
Hi, I need help please.

I have 2 problems in the foll qry:

1. I'm trying to automatically set the var @SartDate / @EndDate

This works:
SET @StartDate = '01-jan-09'
SET @EndDate = '31-dec-09'

This dont work:
--select @StartDate = replace(convert(varchar,max(Split_Date),6),' ','-') from dbo.MIS_SplitFactor
--select @EndDate = replace(convert(varchar,DATEADD(dd,-1,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,@StartDate)+1,0))),6),' ','-')

WHILE @StartDate < @EndDate
BEGIN
INSERT INTO @TempTable
(dates)
VALUES
(@StartDate)
SET @StartDate = dateadd(day,1,@startdate)
END

The result in the Select @Startdate is in the same format of the Set @Startdate = '01-jan-09'

2. The result returned is: 2009-01-01 00:00:00
I want to convert to: 01/01/2009 00:00:00

Regards

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2008-12-24 : 04:00:45
Use Convert Function To get the date in the format u want

Jai Krishna
Go to Top of Page

ismailc
Constraint Violating Yak Guru

290 Posts

Posted - 2008-12-24 : 04:29:41
Thank You i got the convert going:

CONVERT(VARCHAR(10), dates, 103) + ' 00:00:00' AS Split_Date

I want the time to be 00:00:00

But no luck on assigning var val from qry

Regards
Go to Top of Page

ismailc
Constraint Violating Yak Guru

290 Posts

Posted - 2008-12-24 : 05:10:25
Hi, I got it going.

My results was filtered out by the: WHILE @StartDate < @EndDate

as the @StartDate was equal to @EndDate

Regards
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2008-12-24 : 05:12:04
Welcome

Jai Krishna
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-25 : 02:13:30
this is purely a presentation formatting issue which should be done at front end as far as possible. You can very easily get dates in format you want using formatting functions which are available at front end application tools.
Go to Top of Page
   

- Advertisement -