SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Code snippet for CTE

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
Code snippet for CTE
Author Message
ssandu



Joined: 26 Feb 2007
Posts: 95
Country: Romania

Post Code snippet for CTE Reply with quote
Hi
I am trying to make a code snippet for SQL Server's CTE
Something like
SET NOCOUNT ON;
WITH somemane (columns)
AS
(
SELECT columns from sometable
)
is it possible ?
with
$PROMPT(proc_name,Cum se numeste CTE)$

SET NOCOUNT ON;
WITH $proc_name$ ( $COLUMNS$ )
AS
(
select $COLUMNS$ from $OBJECT$ where |
)
select * from $proc_name$
I can't get table name on $OBJECTS$
it's only dbo
Thank's
Mon Nov 19, 2012 6:39 am View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 2109

Post Reply with quote
I needed something similar ages ago and created a snippet for it. It has gone through several modifications since then. You hardly ever need to select all the columns or without any filtering, hence to obtain some flexibility here, it rather works on select queries than on individual tables. But the same effect can be achieved if you apply it to an 'select column1, column2 as whatever, ... from table where blablabla'. And you're free to alter it in any way you want, of course, therefore you can reduce it to pick a table from the popup. It also includes option for creating a table variable or temporary table. Check it here.

EDIT: it might need some modifications to work with SA earlier than 6.3.135 Pro.
Mon Nov 19, 2012 7:43 am View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.