`

sql 这样写,有什么好处?函数列在字段里

阅读更多
表格:aat  两个字段:a,b
select dbo.getmydata(b)  from aat
CREATE TABLE [dbo].[aaT](
[a] [int] NULL,
[b] [int] NULL
)

insert into aat values('1','1')
insert into aat values('1','2')
insert into aat values('1','3')
insert into aat values('1','4')
insert into aat values('1','5')

这样写,有什么好处?

CREATE FUNCTION getmydata
(
-- Add the parameters for the function here
  @id int
)
RETURNs int
AS

begin
   declare @f int
  -- Add the SELECT statement with parameter references here
SELECT @f=b from aat where a=@id
   return @f
end


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics