Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
concatenate dates for two distinct cases
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
CREATE table #tmp (Nummer int, Betreff varchar(32) null, Datum date null ); INSERT INTO #tmp SELECT 1,'2.000 EUR Rente','2017-03-06' UNION ALL SELECT 1,'2.000 EUR Rente',NULL UNION ALL SELECT 1,'2.000 Rente','2017-03-04' UNION ALL SELECT 1,'2.000 Rente','2017-02-02' UNION ALL SELECT 1,'2.000 Rente','2017-03-12' UNION ALL SELECT 1,'2.000 Rente','2017-02-19' UNION ALL SELECT 1,'2.000 Rente','2017-03-19' UNION ALL SELECT 1,'2.000 Rente','2017-02-27' UNION ALL SELECT 1,'2.000 Rente',NULL UNION ALL SELECT 1,'2.000 Rente','2017-02-27' UNION ALL SELECT 1,'2.000 Rente',NULL UNION ALL SELECT 2,'2.000 EUR Rente','2017-03-06' UNION ALL SELECT 2,'2.000 EUR Rente',NULL UNION ALL SELECT 2,'2.000 Rente','2017-03-04' UNION ALL SELECT 2,'2.000 Rente','2017-02-12' UNION ALL SELECT 2,'2.000 Rente','2017-03-12' UNION ALL SELECT 2,'2.000 Rente','2017-02-19' UNION ALL SELECT 2,'2.000 Rente','2017-03-29' UNION ALL SELECT 2,'2.000 Rente','2017-02-27' UNION ALL SELECT 2,'2.000 Rente',NULL UNION ALL SELECT 2,'2.000 Rente','2017-02-27' UNION ALL SELECT 2,'2.000 Rente',NULL; SELECT min(Datum) miDat, max(Datum) maDat, STUFF( (SELECT ','+char(10) + CONVERT(char(10),Datum,104) FROM #tmp WHERE NOT Datum is null AND Nummer=1 ORDER BY Datum FOR XML PATH('')), 1, 2, '' ) as dates1, STUFF( (SELECT ','+char(10) + CONVERT(char(10),Datum,104) FROM #tmp WHERE NOT Datum is null AND Nummer=2 ORDER BY Datum FOR XML PATH('')), 1, 2, '' ) as dates2 FROM #tmp drop table #tmp
View schema
Execution time: 0,02 sec, rows selected: 1, rows affected: 22, absolute service time: 0,17 sec
edit mode
|
history
|
discussion
miDat
maDat
dates1
dates2
1
02.02.2017 00:00:00
29.03.2017 00:00:00
02.02.2017, 19.02.2017, 27.02.2017, 27.02.2017, 04.03.2017, 06.03.2017, 12.03.2017, 19.03.2017
12.02.2017, 19.02.2017, 27.02.2017, 27.02.2017, 04.03.2017, 06.03.2017, 12.03.2017, 29.03.2017
stackse - search stackoverflow differently