Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select in stead off print

Status
Not open for further replies.

annemie

Programmer
Joined
Nov 22, 2002
Messages
7
Location
BE
Hello,

i'm trying to display a table in an asp page witch contains 5 columns, 2 of them calculate the workdays(only weekdays) between two dates and a 3de the difference in workdays from the provious columns. The 2 remaining colums are projetinformation.
I found out how to calculate the workdays in sql en this seems to be ok. Bu i can only use the print function in the query analyser. How do i get this 3 calculations + the 2 projectionfomation items in one query.

DECLARE @Lastdate smalldatetime, @StartDate smalldatetime, @EndDate smalldatetime, @Counter1 tinyint, @Counter2 tinyint, @difference int
SET @StartDate = (select createdate from projects Where Projects_ID=1)
SET @EndDate = (select Deadline from projects Where Projects_ID=1)
SET @Lastdate = (select Lastupdatestatus from projects Where Projects_ID=1)
SET @Counter1= 0
SET @Counter2= 0

WHILE @StartDate <= @EndDate
BEGIN
IF DATEPART(weekday,@StartDate) BETWEEN 2 AND 6
BEGIN
SET @Counter1 = @Counter1 + 1
END
SET @StartDate = DATEADD(day,1,@StartDate)
END

Print @Counter1

SET @StartDate = (select createdate from projects Where Projects_ID=1)

WHILE @StartDate <= @LastDate
BEGIN
IF DATEPART(weekday,@StartDate) BETWEEN 2 AND 6
BEGIN
SET @Counter2 = @Counter2 + 1
END
SET @StartDate = DATEADD(day,1,@StartDate)
END

PRINT @Counter2

Set @difference = @Counter1 - @Counter2
PRINT @difference


Thanks Annemie
 
What do you mean by &quot;i can only use the print function in the query analyser?&quot; Why the limitation? Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains &quot;Suggestions for Getting Quick and Appropriate Answers&quot; to your questions.
 
Try removing the PRINTs and adding as the last line:
Select @counter1, @Counter2, @difference

or better still
Select @Counter1 as Counter1, @Counter2 as Counter2, @Difference as Difference
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top