Hi All
I have this Table:
Name: One
[pre]
ID Name Status Reason StartTime
1 Chris Busy Personal 2013-02-22 06:20:23.100
2 Chris Busy Case Related 2013-02-22 06:21:44.100
3 Chris Busy Lunch 2013-02-22 06:22:56.100
4 Chris Busy Available 2013-02-22 07:22:10.100
5 Mantsha Busy Personal 2013-02-22 06:20:56.100
6 Mantsha Busy Case Related 2013-02-22 06:21:22.100
7 Mantsha Busy Lunch 2013-02-22 06:26:16.100
8 Mantsha Busy Available 2013-02-22 07:18:16.100
9 Mantsha Busy Lunch 2013-02-22 07:18:16.100
[/pre]
Then i used this Function to manipulated the table so that it can be easly accessed by the SSRS Report
Then i ran this query
Then i got this results
[pre]
ID Name Status Reason StartTime
9 Mantsha Busy Lunch 2013-02-22 07:18:16.100
[/pre]
While i was expecting this results
[pre]
ID Name Status Reason StartTime
7 Mantsha Busy Lunch 2013-02-22 06:26:16.100
9 Mantsha Busy Lunch 2013-02-22 07:18:16.100
[/pre]
Then I decided to use a cursor thinking i will get the right results
This is the Cursor:
Then i got this results:
[pre]
ID NAME Status Reason Starttime
9 Mantsha Busy Lunch 2013-02-22 07:18:16.100
ID NAME Status Reason Starttime
9 Mantsha Busy Lunch 2013-02-22 07:18:16.100
[/pre]
Please help me get the right results using this Function
I have this Table:
Name: One
[pre]
ID Name Status Reason StartTime
1 Chris Busy Personal 2013-02-22 06:20:23.100
2 Chris Busy Case Related 2013-02-22 06:21:44.100
3 Chris Busy Lunch 2013-02-22 06:22:56.100
4 Chris Busy Available 2013-02-22 07:22:10.100
5 Mantsha Busy Personal 2013-02-22 06:20:56.100
6 Mantsha Busy Case Related 2013-02-22 06:21:22.100
7 Mantsha Busy Lunch 2013-02-22 06:26:16.100
8 Mantsha Busy Available 2013-02-22 07:18:16.100
9 Mantsha Busy Lunch 2013-02-22 07:18:16.100
[/pre]
Then i used this Function to manipulated the table so that it can be easly accessed by the SSRS Report
Code:
Create Function Agents(@NewReason varchar(20), @NewName varchar(20))
Returns @AgentsInfo Table (
ID int NULL,
Name varchar(20) NULL,
Status varchar(50) NULL,
Reason varchar(50) NULL,
StartTime datetime NULL
)
AS
BEGIN
DECLARE
@ID int,
@Name varchar(20),
@Status varchar(50),
@Reason varchar(50),
@StartTime datetime;
SELECT @ID = ID,
@Name = NAME,
@Status = STATUS,
@Reason = REASON,
@StartTime = Starttime
From One
Where Reason = @NewReason
And Name = @NewName;
IF @ID IS NOT NULL
BEGIN
INSERT @AgentsInfo
SELECT @ID, @Name, @Status, @Reason, @StartTime;
END;
RETURN;
END;
Then i ran this query
Code:
Select * From Agents('Personal', 'Mantsha')
Then i got this results
[pre]
ID Name Status Reason StartTime
9 Mantsha Busy Lunch 2013-02-22 07:18:16.100
[/pre]
While i was expecting this results
[pre]
ID Name Status Reason StartTime
7 Mantsha Busy Lunch 2013-02-22 06:26:16.100
9 Mantsha Busy Lunch 2013-02-22 07:18:16.100
[/pre]
Then I decided to use a cursor thinking i will get the right results
This is the Cursor:
Code:
DECLARE
@ID int,
@Name varchar(20),
@Status varchar(50),
@Reason varchar(50),
@StartTime datetime;
Declare AgentManip Cursor
For
Select * From Agents('Lunch', 'Mantsha')
Open AgentManip
FETCH NEXT FROM AgentManip INTO @ID, @Name, @Status, @Reason, @StartTime
Select @ID ID, @Name NAME, @Status Status, @Reason Reason, @StartTime Starttime
WHILE @@FETCH_STATUS = 0
BEGIN
Select @ID ID, @Name NAME, @Status Status, @Reason Reason, @StartTime Starttime
FETCH NEXT FROM AgentManip INTO @ID, @Name, @Status, @Reason, @StartTime
END;
CLOSE AgentManip
DEALLOCATE AgentManip
Then i got this results:
[pre]
ID NAME Status Reason Starttime
9 Mantsha Busy Lunch 2013-02-22 07:18:16.100
ID NAME Status Reason Starttime
9 Mantsha Busy Lunch 2013-02-22 07:18:16.100
[/pre]
Please help me get the right results using this Function