Forums » Toad for SQL Server Beta

Thread: INSERT INTO (...) SELECT ...


Permlink Replies: 0 - Pages: 1 Threads: [ Previous | Next ]
DarrenM


Posts: 167
Registered: 2/17/10
INSERT INTO (...) SELECT ...
Posted: Apr 16, 2012 12:36 PM
  Click to reply to this thread Reply





When you use the new (…) SELECT … option to build a SQL statement,
the select part of it uses this syntax, with a pre-defined value of
“0” for most fields:

, 0 AS BaseGroup -- BaseGroup - nvarchar(12)

, 0 AS Colour -- Colour - nvarchar(8)

, 0 AS [Size] -- Size - nvarchar(5)

As long as I replace the 0 placeholder with what I want that’s great, but
I would prefer to have it pay attention to the datatype and nullability of the
field and change the value based on that.

i.e. if text and nullable, then

, NULL AS BaseGroup

If text and non nullable, then:

, '' AS BaseGroup

If some number data type, and nullable, then:

, NULL as MyNumber

If some number data type and not nullable then:

, 0 as MyNumber

Doing that would allow me to skip certain fields without worrying about
un-expected values.

Darren



Darren
Legend
Guru: 2001 + pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums