方法一(临时表变量)
Create PROCEDURE [dbo].[Years_ViewList]
@QueryParameter NVARCHAR(100)=''
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
--显示年份2020至2100年
DECLARE @Years NVARCHAR(max)
DECLARE @i NVARCHAR(20)
DECLARE @temps TABLE
(
Years NVARCHAR(100)
)
SET @i =2020
WHILE @i<2098
BEGIN
SET @Years=@i+1
WHILE @Years <=2098
BEGIN
SET @Years=@Years+1
INSERT INTO @temps
(
Years
)
VALUES
( @Years-- Years - nvarchar(100)
)
END
BREAK;
END
END
--查询临时表数据并抛给前端展示--
SELECT Years AS '请选择年份' FROM @temps
方法二 (创建临时表用了要记得删除)
CREATE PROCEDURE [dbo].[Years_ViewList]
@QueryParameter NVARCHAR(100)=''
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
--显示年份2020至2100年
DECLARE @Years NVARCHAR(max)
DECLARE @i NVARCHAR(20)
CREATE TABLE #temps
(
Years NVARCHAR(100)
)
SET @i =2020
WHILE @i<2098
BEGIN
SET @Years=@i+1
WHILE @Years <=2098
BEGIN
SET @Years=@Years+1
INSERT INTO #temps
(
Years
)
VALUES
( @Years-- Years - nvarchar(100)
)
END
BREAK;
END
END
--查询临时表数据并抛给前端展示--
SELECT Years AS '请选择年份' FROM #temps