| | |
Union identical tables in one view
Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved |
0
#2 21 Days Ago
You can create a view dynamically in the following way:
MS SQL Syntax (Toggle Plain Text)
Declare @SQL nVarChar(1000) SELECT @SQL = 'Create View Auths AS (SELECT au_id, au_lname, au_fname FROM Authors)' Execute pubs.dbo.sp_executesql @sql
MARK AS SOLVED if its help you.
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
•
•
Join Date: Nov 2009
Posts: 6
Reputation:
Solved Threads: 0
0
#3 20 Days Ago
Thanks for your answer. Sorry I give a better explanation.
Currently I have solved the union problem by creating a cursor and creating a new table to insert all other tables.
Here I created the cursor with all the tables I want to combine. The tables have identical structure.
Currently I have solved the union problem by creating a cursor and creating a new table to insert all other tables.
MS SQL Syntax (Toggle Plain Text)
DECLARE CURSOR_TABLES CURSOR FOR SELECT name FROM sys.TABLES WHERE name LIKE '%TABLE-%
Here I created the cursor with all the tables I want to combine. The tables have identical structure.
MS SQL Syntax (Toggle Plain Text)
OPEN CURSOR_TABLES FETCH NEXT FROM CURSOR_TABLES INTO @TableName WHILE @@FETCH_STATUS <> -1 BEGIN SET @SQLInsertCmd = 'INSERT INTO dbo.TABLE SELECT table_names FROM ' + @TableName EXEC (@SQLInsertCmd) FETCH NEXT FROM CURSOR_TABLES INTO @TableName END
•
•
Join Date: Nov 2009
Posts: 6
Reputation:
Solved Threads: 0
0
#4 20 Days Ago
Actually I found out I can use my Cursor to create a sql statement
MS SQL Syntax (Toggle Plain Text)
CREATE VIEW ViewTables AS SELECT * FROM table1 UNION ALL SELECT * FROM table2 ...
![]() |
Similar Threads
- OCA study material (Oracle)
- Update Multiple Tables with a Single Form (MS Access and FileMaker Pro)
- how to convert sql server database to access database (MS SQL)
- Table display in swing (Java)
- View Help and calculations (MS SQL)
- VB6 or VBA - Copy table contents from one database to identical database (Visual Basic 4 / 5 / 6)
- Column Aliases (MS SQL)
- MySQL Multiple Table Search (MySQL)
- Prblem with sql sever connection (ASP.NET)
Other Threads in the MS SQL Forum
- Previous Thread: insert date
- Next Thread: SSIS Variable is Empty
| Thread Tools | Search this Thread |





