如何从这个查询创建视图? [英] How to create view from this query?
本文介绍了如何从这个查询创建视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨。
i有这个查询Form 2 Table,我需要创建View或Function。
我的查询:
hi.
i have this query Form 2 Table and I need to create View Or Function.
my Query:
Declare @AghlamTitle_Topic nvarchar(max)
Declare @query nvarchar(max)
Select @AghlamTitle_Topic = stuff((select distinct ','+QuoteName([TopicTitle]) from Tbl_Topic where Topic_PID=29 for xml path('')),1,1,'')
Set @Query = ' Select * from (
Select t2.Aghlam_Marasemat_PID ,t2.[AghlamDateReg], t1.[TopicTitle], t2.AghlamCount from Tbl_Aghlam_Num t2 inner join Tbl_Topic t1
on t2.Aghlam_TopicID_Aghlam = t1.TopicID ) a
pivot (max([AghlamCount]) for [TopicTitle] in ( ' +@AghlamTitle_Topic + ' ) ) p '
exec sp_executeSql @query
我尝试过:
i try :
What I have tried:
i try:
Create View Test
Declare @AghlamTitle_Topic nvarchar(max)
Declare @query nvarchar(max)
Select @AghlamTitle_Topic = stuff((select distinct ','+QuoteName([TopicTitle]) from Tbl_Topic where Topic_PID=29 for xml path('')),1,1,'')
Set @Query = ' Select * from (
Select t2.Aghlam_Marasemat_PID ,t2.[AghlamDateReg], t1.[TopicTitle], t2.AghlamCount from Tbl_Aghlam_Num t2 inner join Tbl_Topic t1
on t2.Aghlam_TopicID_Aghlam = t1.TopicID ) a
pivot (max([AghlamCount]) for [TopicTitle] in ( ' +@AghlamTitle_Topic + ' ) ) p '
exec sp_executeSql @query
如果创建视图不起作用,这个函数是好方法吗?
如何创建函数?
if create view does not Work , Is the function a good way?
How to create a function ?
推荐答案
您无法在视图定义中使用动态查询。
You cannot use dynamic queries in view definition.
这篇关于如何从这个查询创建视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文