日期:2014-05-20  浏览次数:20772 次

一个简单的SQL语句
CREATE VIEW dbo.ZV_InfoProvideCom  
AS  
SELECT dbo.ComBasicInfor.companyName, dbo.ProvideInfor.id, dbo.ProvideInfor.infoTitle,  
  dbo.ProvideInfor.infoText, dbo.ProvideInfor.pubTime, dbo.ProvideInfor.endTime,  
  dbo.ProvideInfor.SearchKeyWord, dbo.ComBasicInfor.linkManName,  
  dbo.ComBasicInfor.linkManHandSet, dbo.ComBasicInfor.linkManPhone,  
  dbo.ComBasicInfor.linkManEmail, dbo.ComBasicInfor.linkManPosition,  
  dbo.ComBasicInfor.comProvince, dbo.ComBasicInfor.comCity,  
  dbo.ComBasicInfor.addressDetails, dbo.ComBasicInfor.comID,  
  dbo.ComBasicInfor.shopStyleId, dbo.ComBasicInfor.linkManCardStyle,  
  dbo.MemberLogin.WhichChengID, dbo.ComBasicInfor.ComBasicInforType  
FROM dbo.ComBasicInfor INNER JOIN  
  dbo.ProvideInfor ON dbo.ComBasicInfor.comID = dbo.ProvideInfor.comID INNER JOIN  
  dbo.MemberLogin ON dbo.ProvideInfor.comID = dbo.MemberLogin.comID  


CREATE proc G_SelProInfor
(  
@time int  
)  
as  
   
select ZV_InfoProvideCom.id, ZV_InfoProvideCom.infoTitle,ZV_InfoProvideCom.infoText,convert(char(10),ZV_InfoProvideCom.pubTime,21)  
 as pubTime,'0'as category into #b from ZV_InfoProvideCom  
inner join ComBasicInfor on ComBasicInfor.comId=ZV_InfoProvideCom.comId  
where ComBasicInfor.IsShenHe='1' and (datediff(day, ZV_InfoProvideCom.pubTime, getdate()))<@time  
order by ZV_InfoProvideCom.pubTime desc  
insert into #b select id,inforTitle as infoTitle,inforText as infoText,convert(char(10),pubTime,21)as pubTime,'1'as category from  
gongqiuheInfor where Type=1 and IsCheck=1 and (datediff(day,pubTime,getdate()))<@time  
select id,infoTitle,infoText,pubTime,category from #b order by PubTime desc  


存储过程中的:select ZV_InfoProvideCom.id, ZV_InfoProvideCom.infoTitle,ZV_InfoProvideCom.infoText,convert(char(10),ZV_InfoProvideCom.pubTime,21)  
 as pubTime,'0'as category into #b from ZV_InfoProvideCom  
这个ZV_InfoProvideCom中的id,infoTitle,....代表什么呢?还有这个#b 是不是一个临时表呢?
请详解一下,谢谢各位!  


------解决方案--------------------
ZV_InfoProvideCom
是视图,
你直接在SQL中 运行 select * from ZV_InfoProvideCom
就知道id,infoTitle是什么了,是其他表中的字段!
------解决方案--------------------
ZV_InfoProvideCom 是一个视图
id,infoTitle 是 dbo.ProvideInfor表中的字段 需要你自己去看是什么意思
#b 是一个虚表
------解决方案--------------------
对多个表进行数据统计的时候用视图增加性能。。。可以只对这视图表进行查询,分析。
------解决方案--------------------
pubTime,category 是新定义的字段名。