Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:06:06+00:00 2026-06-05T02:06:06+00:00

I very rarely use SQL Server and in a professional context I keep well

  • 0

I very rarely use SQL Server and in a professional context I keep well clear! I’m working on a pet project though and I’m have problems with a script creation.

I’ve got an online database that I need to extract everything out of. I use the Tasks > Generate Scripts option within SQL Server Management Studio. The following is an example of one insert statement the script creates (I have 1,000s of these inserts):

INSERT [dbo].[NewComics] ([NewComicId], [Title], [Subtitle], [ReleaseDate], [CollectionId]) VALUES (366, N'Hawk & Dove 1:                                                                                      ', N'First Strikes                                                                                       ', CAST(0x00009F6F00000000 AS DateTime), 248)

I have two issues with this:

(a) I want to strip all the whitespace from the two title elements
(b) I don’t want a HEX date – I want something readable like 2006-09-01 (yyyy-mm-dd)

INSERT [dbo].[NewComics] ([NewComicId], [Title], [Subtitle], [ReleaseDate], [CollectionId]) VALUES (366, N'Hawk & Dove 1:', N'First Strikes', '2006-09-01', 248)

What would be the quickest way to change about 3,000 insert statements to this revised format?

FYI – this is the design of the table:

[NewComicId] [int] NOT NULL,
[Title] [nchar](100) NOT NULL,
[Subtitle] [nchar](100) NULL,
[ReleaseDate] [datetime] NOT NULL,
[CollectionId] [int] NOT NULL,

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:06:07+00:00Added an answer on June 5, 2026 at 2:06 am

    Yes, generate scripts sadly scripts datetime columns as CONVERT(binary_value, Datetime). I’ll try to get an answer as to why (or more importantly if there is a way to change the behavior). I suspect the reason is to avoid any issues with running the scripts on a different machine with different locale / regional settings etc. I don’t know if there’s a way to change that from happening in the meantime, but Management Studio isn’t the only way to script your data… you could look into 3rd party products like Red-Gate’s SQL Data Compare.

    If it’s really only 3,000 rows, and you intend to run the generated script on a different server, stop using the wizard and do this (on first glance this looks horrific, but it does several of the things you’ll want – outputs a script ready to copy, paste and run, with nicely formatted and readable dates, inserts batched into multi-row VALUES by 1000 with GO commands in between, and even deals with potentially NULL values in title, subtitle and collectionid):

    DECLARE @newtable SYSNAME = 'dbo.NewComics';
    
    SET NOCOUNT ON;
    
    ;WITH x AS (SELECT TOP (4000) s = '(' 
        + CONVERT(VARCHAR(12), NewComicId) + ','
        + COALESCE('N''' + REPLACE(RTRIM(Title), '''', '''''') + '''', 'NULL') + ',' 
        + COALESCE('N''' + REPLACE(RTRIM(SubTitle), '''', '''''') + '''', 'NULL') 
        + ', ''' + CONVERT(CHAR(8), ReleaseDate, 112) + ' '
        + CONVERT(CHAR(8), ReleaseDate, 108) + ''','
        + CONVERT(VARCHAR(12), COALESCE(CollectionId, 'NULL')) + ')',
      rn = ROW_NUMBER() OVER (ORDER BY NewComicId)
      FROM dbo.OldComics ORDER BY NewComicId
    ),
    y AS
    (
    SELECT [/*a*/] = 1, [/*b*/] = 'SET NOCOUNT ON;
    GO
    INSERT ' + @newtable + ' VALUES'
    UNION ALL 
    SELECT 2, s = CASE WHEN rn > 1 THEN ',' ELSE '' END + s
     FROM x WHERE rn BETWEEN 1 AND 1000
    UNION ALL 
    SELECT 3, 'GO' UNION ALL 
    SELECT 4, s = CASE WHEN rn > 1001 THEN ',' ELSE '' END + s
     FROM x WHERE rn BETWEEN 1001 AND 2000
    UNION ALL 
    SELECT 5, 'GO' UNION ALL 
    SELECT 6, s = CASE WHEN rn > 2001 THEN ',' ELSE '' END + s
     FROM x WHERE rn BETWEEN 2001 AND 3000
    UNION ALL 
    SELECT 7, 'GO' UNION ALL 
    SELECT 8, s = CASE WHEN rn > 3001 THEN ',' ELSE '' END + s
     FROM x WHERE rn BETWEEN 3001 AND 4000
    )
    SELECT [/*b*/] FROM y ORDER BY [/*a*/];
    

    (You might have to play with it if you have exactly 3000 or 3001 rows, or add another couple of unions if you have more than 4000, etc.)

    If you are moving the data to a different table or different database on the same instance, use the script that @swasheck provided (and again, stop using the wizard).

    You may have noticed a common trend here: stop using the generate scripts wizard if you don’t like the binary format it outputs for dates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I very rarely use fortran, however I have been tasked with taking legacy code
Very easy question. I have been using CSS for a while but rarely use
I have a variable that very rarely gets an incorrect value. Since the system
I have a situation where very rarely a Queue of Objects is dequeuing a
I have a client that I am doing a very small project for. His
I'm completely new to C and I use it very rarely. This time i
I have a friend that uses facebook very rarely. What I would like to
At the office, when I leave for the night I very rarely log off
Very basic question - but I couldn't find an answer. I have got a
What are peoples' opinions on using the __call__ . I've only very rarely seen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.