Hi Jose,
I'm sorry but i don't succeed to reproduce the problem
This is the T-SQL statement where I try your issues but it works
----
use tempdb
go
Create Table Setusers
([Login] varchar(30),
iStdt datetime,
iDate datetime,
Area CHAR(3))
/* insert values in Setusers
My Login name is Rancati */
INSERT Setusers
VALUES('perdijc','20060101','20060105','SFA')
INSERT Setusers
VALUES('jeff','20060106','20060110','CFA')
INSERT Setusers
VALUES('Rancati','20060111','20060115','HFA')
GO
/* FUNCTION iLogin */
CREATE FUNCTION dbo.iLogin (@Type bit)
RETURNS varchar(30)
AS
-- @Type 0 returns Domain
-- 1 returns user
BEGIN
/* Sql Server autentication mode */
IF CharIndex('\',system_user)=0
RETURN system_user
/* Windows Autentication mode */
--Domain
IF @Type=0
RETURN LEFT(system_user,CharIndex('\',system_user)-1)
--User
RETURN SUBSTRING(system_user,CharIndex('\',system_user)+1,30)
END
GO
/* VIEW iUserCrt*/
Create view iUserCrt
AS
SELECT dbo.Setusers.*
FROM dbo. Setusers
WHERE (Login = dbo.iLogin(1))
GO
/* FUNCTION dbo.iDate */
CREATE FUNCTION dbo.iDate ()
RETURNS datetime
AS
BEGIN
RETURN (SELECT iDate FROM dbo.iUserCrt )
END
GO
/* FUNCTION dbo.iStdt */
CREATE FUNCTION dbo.iStdt ()
RETURNS datetime
AS
BEGIN
RETURN (SELECT iStdt FROM dbo.iUserCrt )
END
GO
/* Test Table */
CREATE TABLE Tab1
(MyDate DATETIME)
GO
Insert Tab1
SELECT '20060101' UNION
SELECT '20060102' UNION
SELECT '20060103' UNION
SELECT '20060104' UNION
SELECT '20060105' UNION
SELECT '20060106' UNION
SELECT '20060107' UNION
SELECT '20060108' UNION
SELECT '20060109' UNION
SELECT '20060110' UNION
SELECT '20060111' UNION
SELECT '20060112' UNION
SELECT '20060113' UNION
SELECT '20060114' UNION
SELECT '20060115' UNION
SELECT '20060116' UNION
SELECT '20060117' UNION
SELECT '20060118' UNION
SELECT '20060119' UNION
SELECT '20060120'
GO
/* functions result */
SELECT dbo.iStdt() iStd ,
dbo.iDate() iDate ,
dbo.iLogin(1) iLogin
/******************************
The Select
******************************/
SELECT *
FROM Tab1
WHERE Mydate BETWEEN dbo.iStdt() AND dbo.iDate()
/* Clean database */
Drop View dbo.iUserCrt
Drop Function dbo.iDate ,dbo.iStdt,dbo.iLogin
Drop Table SetUsers,Tab1
----
Result
iStd iDate iLogin
------------- ------------ ---------
2006-01-11 2006-01-15 Rancati
MyDate
---------------
2006-01-11
2006-01-12
2006-01-13
2006-01-14
2006-01-15
SELECT @@Version
-----
Microsoft SQL Server 2000 - 8.00.2040 (Intel X86)
May 13 2005 18:33:17
Copyright (c) 1988-2003 Microsoft Corporation
Personal Edition on Windows NT 5.0 (Build 2195: Service Pack 4)