tags:

views:

80

answers:

4

I've been working on an application that has no discernable data access layer, so all the SQL statements are just built up as strings and executed. I'm constantly confronted by very long INSERT statements where I'm trying to figure out what value in the VALUES list matches up with what column in the column name list.

I was about to create a little helper application where I could paste in an INSERT statement and have it show me a list of values matched up with the column names, just for debugging, and I thought, "someone else has probably done this already."

Does anyone know of a web site where I can just paste in an INSERT statement and have it show me a two column table with column names in the first column and values in the second column?

+4  A: 

not a website but have you tried either visual studio or Sql Server Management studio. Both of these are able to do this.

Nathan Fisher
Ah, yes. You can paste the query into a window and then click the Design Query in Editor button on the toolbar. Very useful, thanks!
Scott Whitlock
Just an extra note: you have to highlight the query text before you click the Design Query in Editor button.
Scott Whitlock
+1  A: 

http://www.dpriver.com/pp/sqlformat.htm

adolf garlic
I can't figure out how to make this do what I'm asking. What options am I supposed to select?
Scott Whitlock
+2  A: 

You can use SQL Server Management studio or Visual Studio (with Server Explorer) to do that. For SSMS, follow these steps:

  1. On a random table, click "Edit Top 200 Rows"
  2. Open the SQL pane and paste your Insert script.
  3. Open the Criteria Pane, which displays the insert column value pairs.
Prutswonder
A: 

I use Red Gate SQL Prompt for all my re-formatting.

Even though it is unnecessary (and unused), I often use aliases to make it easier to line things up, so instead of:

INSERT INTO tbl
SELECT 2 * y
FROM other_tbl

I usually do:

INSERT INTO tbl (x)
SELECT 2 * y AS x
FROM other_tbl
Cade Roux
It is a great product, but it isn't free. Something like 200$ a licence.If you code T-SQL on a daily basis, you must buy it.
adolf garlic