User Profile

Collapse

Profile Sidebar

Collapse
Greg Stowell
Greg Stowell
Last Activity: Oct 7 '10, 12:05 AM
Joined: Sep 10 '10
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Example of concept posted above:

    Code:
    drop table dummy
    go
    
    CREATE TABLE dummy
    (
    	thetext varchar(10)
    )
    
    go
    
    insert into dummy values ('ABDC')
    insert into dummy values ('CDEF')
    insert into dummy values ('EFGH')
    insert into dummy values ('HIJK')
    insert into dummy values ('LMNO')
    insert into dummy values ('PQRS')
    insert into dummy
    ...
    See more | Go to post

    Leave a comment:


  • Possibly add a column to the table with an integer defined, and assign identity to the field, then remove it (just to number it once) - and each time you run the query (and order by that integer) - you can take the min(integer) and make it max(integer)+1, and just to make sure you don't go over the 65535 (or whatever size # you assign) - perhaps do an update table set integer = integer -1 at the end.
    See more | Go to post

    Leave a comment:


  • I forgot - Notice the varchar(8000) on the @query?
    Be careful how many tables you pull in.. go over that 8000 chars, and it gets truncated.

    Good luck, and let me know if the concept helps, or if you get any errors, I can help debug (kinda busy at work - so my replies may take some time).
    See more | Go to post

    Leave a comment:


  • This might be what you're looking for - its in a stored proc format - but you could switch it around to be a function without much trouble...

    Code:
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE dbo.[sp_UnionEm]
    
    AS
    
    BEGIN
    
    DECLARE @tablenames varchar(8000)
    DECLARE @query varchar(8000)
    
    DECLARE aCursor Cursor for
    
    SELECT
    ...
    See more | Go to post

    Leave a comment:


  • You mentioned all of the tables contain the same column names....

    Do all of the tables have the same data types, same number of columns (with the columns ordinal positions all the same), and you're just looking to create something to do dynamic SQL to union them all together?
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...