/// Frank Hagen: Professional Web Developer, C# User, Reformed Über-geek RSS 2.0
# Monday, February 18, 2008

It is fair to say that I don't do a huge amount of real-time SQL.  As an application developer, the vast majority of SQL I write is in Stored Procedures and packages.  Very infrequently, I need to do a manual insert statement.  So why do I always forget to drop the VALUES keyword in a T-SQL statement when using a sub-query?  I mean every time!

So here it is.  A representative INSERT statement with sub-query:

insert into UserRoleMembership
(userIdx, roleName)
 
(
  select 488, roleName from Roles
  where appidx = 18
  and roleName not in ( select roleName from UserRoleMembership where userIdx = 488 )
)

Now I won't forget.

Monday, February 18, 2008 11:37:20 AM (Eastern Standard Time, UTC-05:00)  #    Comments [1] -
SQL
Friday, February 29, 2008 4:24:19 PM (Eastern Standard Time, UTC-05:00)
Do you mean to say you were saying like:

Insert into foo (col1, col2)
values (select stuff from elsewhere)

?
Golf Cabalist
All comments require the approval of the site owner before being displayed.
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: b, blockquote@cite, i, strike, strong, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
<%--
--%>
Statistics
Total Posts: 186
This Year: 0
This Month: 0
This Week: 0
Comments: 72
Locations of visitors to this page
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Frank W Hagen
Sign In
All Content © 2010, Frank W Hagen
Custom DasBlog theme based on 'Business' by Christoph De Baene