June 17, 2014 at 12:00 am
Easy one (as I recently read this blogpost: Change data through CTE’s[/url]). Thanks for the question!
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
June 17, 2014 at 12:48 am
I've never thought about insert data in a CTE
June 17, 2014 at 12:58 am
Thanks for question.It reminds me the trick to delete the duplicate records in a table 🙂
--rhythmk
------------------------------------------------------------------
To post your question use below link
https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
🙂
June 17, 2014 at 1:02 am
rhythmk (6/17/2014)
Thanks for question.It reminds me the trick to delete the duplicate records in a table 🙂
Could you enlighten me on that please? It sounds very useful.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
June 17, 2014 at 1:21 am
Thanks for QOD, Barry.
---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
June 17, 2014 at 1:24 am
I never even considered using a CTE for an insert..... interesting.
June 17, 2014 at 2:10 am
I hate DISTINCT *
😛
June 17, 2014 at 3:43 am
June 17, 2014 at 3:51 am
palotaiarpad (6/17/2014)
I hate DISTINCT *😛
"hate" is a strong word, but in this QOTD the DISTINCT is absolutely not necessary.
June 17, 2014 at 4:41 am
BWFC (6/17/2014)
rhythmk (6/17/2014)
Thanks for question.It reminds me the trick to delete the duplicate records in a table 🙂Could you enlighten me on that please? It sounds very useful.
Here you go.
CREATE TABLE #TEMP (ID INT,FNAME VARCHAR(50),LNAME VARCHAR(50))
GO
INSERT INTO #TEMP
SELECT 1,'LIONEL','MESSI' UNION ALL
SELECT 1,'LIONEL','MESSI' UNION ALL
SELECT 1,'LIONEL','MESSI' UNION ALL
SELECT 2,'NEYMAR','SILVA' UNION ALL
SELECT 2,'NEYMAR','SILVA' UNION ALL
SELECT 3,'CHRISTIANO','RONALDO' UNION ALL
SELECT 3,'CHRISTIANO','RONALDO' UNION ALL
SELECT 4, 'THOMAS','MUELLER'
GO
--SELECT * FROM #TEMP
;WITH DUPL AS
(SELECT ID,FNAME,LNAME,ROW_NUMBER() OVER (PARTITION BY ID,FNAME,LNAME ORDER BY ID,FNAME,LNAME) [RN]
FROM #TEMP)
DELETE FROM DUPL WHERE RN <> 1
--SELECT * FROM #TEMP
--DROP TABLE #TEMP
--rhythmk
------------------------------------------------------------------
To post your question use below link
https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
🙂
June 17, 2014 at 5:12 am
CTEs solve so many problems. Thanks for the question.
June 17, 2014 at 5:13 am
This was removed by the editor as SPAM
June 17, 2014 at 5:24 am
rhythmk (6/17/2014)
BWFC (6/17/2014)
rhythmk (6/17/2014)
Thanks for question.It reminds me the trick to delete the duplicate records in a table 🙂Could you enlighten me on that please? It sounds very useful.
Here you go.
CREATE TABLE #TEMP (ID INT,FNAME VARCHAR(50),LNAME VARCHAR(50))
GO
INSERT INTO #TEMP
SELECT 1,'LIONEL','MESSI' UNION ALL
SELECT 1,'LIONEL','MESSI' UNION ALL
SELECT 1,'LIONEL','MESSI' UNION ALL
SELECT 2,'NEYMAR','SILVA' UNION ALL
SELECT 2,'NEYMAR','SILVA' UNION ALL
SELECT 3,'CHRISTIANO','RONALDO' UNION ALL
SELECT 3,'CHRISTIANO','RONALDO' UNION ALL
SELECT 4, 'THOMAS','MUELLER'
GO
--SELECT * FROM #TEMP
;WITH DUPL AS
(SELECT ID,FNAME,LNAME,ROW_NUMBER() OVER (PARTITION BY ID,FNAME,LNAME ORDER BY ID,FNAME,LNAME) [RN]
FROM #TEMP)
DELETE FROM DUPL WHERE RN <> 1
--SELECT * FROM #TEMP
--DROP TABLE #TEMP
I like that, there's another one to add to the toolbox. Thanks.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
June 17, 2014 at 6:09 am
I actually thought "select distinct * ..." might raise an error.
I have never used this and wonder why it would even be allowed.
---------------
Mel. 😎
Viewing 15 posts - 1 through 15 (of 33 total)
You must be logged in to reply to this topic. Login to reply