RETURNS TABLE
AS
DECLARE @iend INT
--SET @ym='2010-06'+'-01'
-- SELECT day(DATEADD(month, 1,@YM )-1)
SET @iend=day(DATEADD(month, 1,@YM )-1)
BEGIN
IF @iend=28
SELECT ym,emp_id,'1' as days ,d1 FROM KQSch
else if @iend=30
SELECT ym,emp_id,'1' as days ,d1 FROM KQSch
UNION ALL
SELECT ym,emp_id,'2' as days ,d2 FROM KQSch
else
@iend=31
SELECT ym,emp_id,'1' as days ,d1 FROM KQSch
UNION ALL
SELECT ym,emp_id,'2' as days ,d2 FROM KQSch
UNION ALL
SELECT ym,emp_id,'3' as days ,d3 FROM KQSch
END
7 个解决方案
#1
CREATE FUNCTION CyFMonthlySCH(@YM dATETIME)
RETURNS @a TABLE(ym VARCHAR(20),emp_id INT,days INT,d INT)
AS
BEGIN
DECLARE @iend INT
--SET @ym='2010-06'+'-01'
-- SELECT day(DATEADD(month, 1,@YM )-1)
SET @iend=day(DATEADD(month, 1,@YM )-1)
IF @iend=28
INSERT @a
SELECT ym,emp_id,'1' as days ,d1 FROM KQSch
else if @iend=30
INSERT @a
SELECT ym,emp_id,'1' as days ,d1 FROM KQSch
UNION ALL
SELECT ym,emp_id,'2' as days ,d2 FROM KQSch
else
INSERT @a
SELECT ym,emp_id,'1' as days ,d1 FROM KQSch
UNION ALL
SELECT ym,emp_id,'2' as days ,d2 FROM KQSch
UNION ALL
SELECT ym,emp_id,'3' as days ,d3 FROM KQSch
END
#2
chuifengde
(树上的鸟儿)
谢谢,有问题还得多请教您,
(树上的鸟儿)
谢谢,有问题还得多请教您,
#3
CREATE FUNCTION CyFMonthlySCH
(
@YM DATETIME
)
RETURNS @r TABLE(ym VARCHAR(20),emp_id VARCHAR(20),days INT,d1 VARCHAR(20))--类型自己修改
AS
BEGIN
DECLARE @iend INT
--SET @ym='2010-06'+'-01'
-- SELECT day(DATEADD(month, 1,@YM )-1)
SET @iend = DAY(DATEADD(MONTH, 1, @YM)-1)
BEGIN
IF @iend=28
INSERT @r
SELECT ym, emp_id, '1' AS days, d1
FROM KQSch
ELSE IF @iend=30
INSERT @r
SELECT *
FROM (
SELECT ym, emp_id, '1' AS days, d1
FROM KQSch
UNION ALL
SELECT ym, emp_id, '2' AS days, d2
FROM KQSch
) t
ELSE
INSERT @r
SELECT *
FROM (
SELECT ym, emp_id, '1' AS days, d1
FROM KQSch
UNION ALL
SELECT ym, emp_id, '2' AS days, d2
FROM KQSch
UNION ALL
SELECT ym, emp_id, '3' AS days, d3
FROM KQSch
) t
END
RETURN
END
GO
#4
好像不能这样实现
#5
TABLE(ym VARCHAR(20),emp_id VARCHAR(20),days INT,d1 VARCHAR(20))--类型自己修改
这个得一定要吗,我看也有这样
CREATE FUNCTION fnGetEmployeesByCity (@sCity VARCHAR(30))
RETURNS TABLE
AS
RETURN
(
SELECT FirstName, LastName, Address
FROM Employees
WHERE City = @sCity
)
GO
这个得一定要吗,我看也有这样
CREATE FUNCTION fnGetEmployeesByCity (@sCity VARCHAR(30))
RETURNS TABLE
AS
RETURN
(
SELECT FirstName, LastName, Address
FROM Employees
WHERE City = @sCity
)
GO
#6
不好意思我已结帖了。多多谢
#7
弱弱的问下,你们这样格工,是用什么工具,2005分析器?
#1
CREATE FUNCTION CyFMonthlySCH(@YM dATETIME)
RETURNS @a TABLE(ym VARCHAR(20),emp_id INT,days INT,d INT)
AS
BEGIN
DECLARE @iend INT
--SET @ym='2010-06'+'-01'
-- SELECT day(DATEADD(month, 1,@YM )-1)
SET @iend=day(DATEADD(month, 1,@YM )-1)
IF @iend=28
INSERT @a
SELECT ym,emp_id,'1' as days ,d1 FROM KQSch
else if @iend=30
INSERT @a
SELECT ym,emp_id,'1' as days ,d1 FROM KQSch
UNION ALL
SELECT ym,emp_id,'2' as days ,d2 FROM KQSch
else
INSERT @a
SELECT ym,emp_id,'1' as days ,d1 FROM KQSch
UNION ALL
SELECT ym,emp_id,'2' as days ,d2 FROM KQSch
UNION ALL
SELECT ym,emp_id,'3' as days ,d3 FROM KQSch
END
#2
chuifengde
(树上的鸟儿)
谢谢,有问题还得多请教您,
(树上的鸟儿)
谢谢,有问题还得多请教您,
#3
CREATE FUNCTION CyFMonthlySCH
(
@YM DATETIME
)
RETURNS @r TABLE(ym VARCHAR(20),emp_id VARCHAR(20),days INT,d1 VARCHAR(20))--类型自己修改
AS
BEGIN
DECLARE @iend INT
--SET @ym='2010-06'+'-01'
-- SELECT day(DATEADD(month, 1,@YM )-1)
SET @iend = DAY(DATEADD(MONTH, 1, @YM)-1)
BEGIN
IF @iend=28
INSERT @r
SELECT ym, emp_id, '1' AS days, d1
FROM KQSch
ELSE IF @iend=30
INSERT @r
SELECT *
FROM (
SELECT ym, emp_id, '1' AS days, d1
FROM KQSch
UNION ALL
SELECT ym, emp_id, '2' AS days, d2
FROM KQSch
) t
ELSE
INSERT @r
SELECT *
FROM (
SELECT ym, emp_id, '1' AS days, d1
FROM KQSch
UNION ALL
SELECT ym, emp_id, '2' AS days, d2
FROM KQSch
UNION ALL
SELECT ym, emp_id, '3' AS days, d3
FROM KQSch
) t
END
RETURN
END
GO
#4
好像不能这样实现
#5
TABLE(ym VARCHAR(20),emp_id VARCHAR(20),days INT,d1 VARCHAR(20))--类型自己修改
这个得一定要吗,我看也有这样
CREATE FUNCTION fnGetEmployeesByCity (@sCity VARCHAR(30))
RETURNS TABLE
AS
RETURN
(
SELECT FirstName, LastName, Address
FROM Employees
WHERE City = @sCity
)
GO
这个得一定要吗,我看也有这样
CREATE FUNCTION fnGetEmployeesByCity (@sCity VARCHAR(30))
RETURNS TABLE
AS
RETURN
(
SELECT FirstName, LastName, Address
FROM Employees
WHERE City = @sCity
)
GO
#6
不好意思我已结帖了。多多谢
#7
弱弱的问下,你们这样格工,是用什么工具,2005分析器?