Author |
Topic |
jfm
Posting Yak Master
145 Posts |
Posted - 2013-07-30 : 11:49:05
|
Hi there, I got many duplicates in T_1 I have Name_col and Date_col. Each Name_col has several different dates and I need the Max date of each name_row. So i will keep the name of my client and the last date instead of the name plus the historical dates. Any tips? Thanks!! |
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2013-07-30 : 12:11:22
|
[CODE]select Name_col, max(Date_col) as maxDatefrom MyTablegroup by Name_col[/CODE]=================================================The cure for anything is salt water -- sweat, tears, or the sea. -Isak Dinesen |
|
|
jfm
Posting Yak Master
145 Posts |
Posted - 2013-07-30 : 13:11:55
|
Perfect. Thanks a lot. I have another question: how im able to subtract one month from a date and create a new column? Imagine i have 2013-07-18 and I need to use a query in SQL that gives me 2013-06-18Thank you!!quote: Originally posted by Bustaz Kool [CODE]select Name_col, max(Date_col) as maxDatefrom MyTablegroup by Name_col[/CODE]=================================================The cure for anything is salt water -- sweat, tears, or the sea. -Isak Dinesen
|
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
jfm
Posting Yak Master
145 Posts |
|
jfm
Posting Yak Master
145 Posts |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
jfm
Posting Yak Master
145 Posts |
Posted - 2013-07-30 : 14:33:59
|
Select col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, dateadd(month, coldate, -1) into new_tablefrom My_tablegroup by col1, col2, col3, col4, col5, col6, col7, col8, col9, col10What im doing wrong? Thank youquote: Originally posted by tkizer There is no issue with using DATADD with millions of dates. Just past it the column name.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
|
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
jfm
Posting Yak Master
145 Posts |
|
|