Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 View SQL code simultaneously

Author  Topic 

Sir_William
Starting Member

6 Posts

Posted - 2011-11-18 : 00:14:31
Perhaps I've missed it in my search, but I'm trying to find a way to view the SQL code of an import I did from Access.

I created the database and table in Access, and after a painful line-by-line insert process, I decided to import it into SQL server 2008. I could not get the Excel spreadsheet to import for some reason.

That said, I would like to view the code of that import...the INSERT statement(s) that went into populating the table with the data, etc.

How do I accomplish this?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-18 : 00:16:41
You'll need to use a generator such as this one: http://vyaskn.tripod.com/code/generate_inserts.txt

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Sir_William
Starting Member

6 Posts

Posted - 2011-11-18 : 00:23:56
Thank you for the prompt reply.
However, you've just lost me. I'm extremely new to SQL, thus the reason for my post in this forum.
Can you provide any additional guidance on how to implement and execute the generator provided.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-18 : 00:28:09
Copy the entire code on the link I posted. Run it on your SQL Server by clicking execute. This saves the code as a stored procedure. Now you need to execute the stored procedure. It can be as simple as this: EXEC sp_generate_inserts 'YourTableName'

Oh and make sure you do this in the database where your table exists.

If you need more flexibility, see the examples in the comment header block of the code as Vyas provides lots of functionality with his generator.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Sir_William
Starting Member

6 Posts

Posted - 2011-11-18 : 01:00:12
OK, I've copied the code and executed it. I'm getting errors.

Here is the output:

Using Master database
Checking for the existence of this procedure
Procedure already exists. So, dropping it
Msg 2812, Level 16, State 62, Line 3
Could not find stored procedure 'master.dbo.sp_MS_upd_sysobj_category'.

Created the procedure
Msg 2812, Level 16, State 62, Line 4
Could not find stored procedure 'master.dbo.sp_MS_upd_sysobj_category'.

Granting EXECUTE permission on sp_generate_inserts to all users
Done

When I run the EXEC sp_generate_inserts 'YourTableName' to generate the INSERT statements I get the following:

Msg 537, Level 16, State 2, Procedure sp_generate_inserts, Line 331
Invalid length parameter passed to the LEFT or SUBSTRING function.
Msg 537, Level 16, State 2, Procedure sp_generate_inserts, Line 332
Invalid length parameter passed to the LEFT or SUBSTRING function.
Msg 50000, Level 16, State 1, Procedure sp_generate_inserts, Line 336
No columns to select. There should at least be one column to generate the output
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-11-18 : 01:05:25
Use Master???

STOP. DO NOT PASS GO. DO NOT DO ANYTHING.

Go get a dba before you destroy everything

NOW...Go to your local bar and slam as many margaritas as you can..I'll be right there...

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-11-18 : 01:06:10
Tara: Do you have a backup?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Sir_William
Starting Member

6 Posts

Posted - 2011-11-18 : 01:09:27
Nothing really to destroy....
I've just created this database, and I've saved it off separately before departing on this adventure.
I'm just looking for a way to view the INSERT statements from the data I've imported to the table from Access.
Go to Top of Page

Sir_William
Starting Member

6 Posts

Posted - 2011-11-18 : 01:24:34
I found the error(s), and I've fixed my problem.
I replaced 'master' with the correct name of my database, and all is well.

Thank you for your help. I look forward to spending more time here learning more and more about SQL, etc.

Cheers!

BTW, Brett, no margaritas here....but I was able to pour a nice single malt over one ice cube... enjoy!
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-11-18 : 01:48:45
NOBODY...pours single malt on the rocks..maybe a splah of distilled water...

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Sir_William
Starting Member

6 Posts

Posted - 2011-11-18 : 02:01:04
Touche'

That said, this Glenlivet 21 does me well with a small 1" frozen drink cube (not really ice).
It's made of some other material that you put in the freezer so as not to water down the drink.
Pardon my Neanderthal ways, it's how I roll... ;)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-11-18 : 02:03:39
It's 5:00 somewhere

What ever floats your boat

2:03 EDT


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -