1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| SET NOCOUNT ON
CREATE TABLE #Tmp (
id1 int IDENTITY PRIMARY KEY,
id2 int)
INSERT INTO #Tmp (id2) VALUES (1)
INSERT INTO #Tmp (id2) VALUES (2)
INSERT INTO #Tmp (id2) VALUES (2)
INSERT INTO #Tmp (id2) VALUES (-1)
INSERT INTO #Tmp (id2) VALUES (3)
INSERT INTO #Tmp (id2) VALUES (0)
INSERT INTO #Tmp (id2) VALUES (6)
INSERT INTO #Tmp (id2) VALUES (-1)
INSERT INTO #Tmp (id2) VALUES (5)
INSERT INTO #Tmp (id2) VALUES (1)
SELECT * FROM #Tmp
SELECT id1,id2,convert(varchar,id2) + '.' + convert(varchar,id1) AS id3
FROM #Tmp
WHERE id2 <> -1
UNION
SELECT id1,id2,convert(varchar,id1) AS id3
FROM #Tmp
WHERE id2 = -1
DROP TABLE #Tmp
SET NOCOUNT OFF |
Partager