You are here: Re: Create view from cursor « MsSQL Server « IT news, forums, messages
Re: Create view from cursor

Posted by Stu on 10/02/17 11:47

This is actually one of the few times that a cursor and dynamic SQL can
be useful; this administrative scripting is a great target for this
sort of stuff.

Anyway, you need to use dynamic SQL for this:

DECLARE @tSite TABLE (site varchar(5))
INSERT INTO @tSite
SELECT 'ABCDE'
UNION ALL
SELECT 'FGHIJ'

declare @site varchar(5)
DECLARE @SQL nvarchar(2000)



declare c_site cursor for
select site from @tsite


open c_site
fetch from c_site
into @site

while (@@fetch_status = 0)
begin

SET @SQL = 'CREATE VIEW Site_All_Data_' + @site + '
AS
SELECT *
FROM dbo.[600_All_Suggested_Data]
WHERE Site = ''' + @site + ''''

exec (@SQL)

Print 'View for ' + @site + ' Created'

fetch next from c_site into @site
end
close c_site
deallocate c_site


HTH,
Stu

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация