Home Forums SQL Server 2005 Backups how to take script for database table data RE: how to take script for database table data

  • You could write a script to BCP out the data?

    Here is something I run to generate data from a table to convert it into a SELECT statement:

    USE MyDatabase

    Go

    DECLARE @Line VARCHAR(max), @TName varchar(128)

    SET @TName = 'MyTable'

    SET @Line = ''

    SELECT @Line = @Line + '+ ISNULL(QUOTENAME('+

    CASE WHEN C.Data_Type IN ('bit','datetime','smalldatetime','date','timestamp','int','smallint','bitint','tinyint', 'money', 'float','decimal','numeric')

    THEN 'CAST('+C.COLUMN_NAME+' as varchar)' ELSE C.COLUMN_NAME END

    +',''''''''),''NULL'')+'',''' FROM information_schema.tables T

    JOIN information_schema.columns C

    ON t.table_name = c.table_name

    WHERE t.table_type = 'base table'

    --and t.table_name like 'L_%'

    and T.Table_Name = @TName

    SELECT 'SELECT ''SELECT ''+'+SUBSTRING(@Line, 3, LEN(@Line) -4)+' UNION'''

    Argue for your limitations, and sure enough they're yours (Richard Bach, Illusions)