Thanks for reading this.
For MS SQL 2008, say you want the results to return:
1. All records from PTemp
2. All records from fTable that's not in PTemp
3. The first record returned should be '^SomeHeader' ..nekey is alpha (a-z).
The following sql returns NULL as the first record instead of '^SomeHeader'.
PTemp and fTable do not have a NULL field for nekey.
If you could help improve the efficiency with the sql that would be appreciated as well:
DECLARE @PTemp TABLE (nekey VARCHAR(30))
INSERT INTO @PTemp (nekey)
WHERE nekey <> ''
AND nekey IS NOT NULL
SELECT '^SomeHeader' as ndcextract
SELECT nekey + '|||'
SELECT f.nekey + '|' + f.field02 + '|' + f.field03 + '|'
FROM DBO.[fTable] f
LEFT JOIN @PTemp p ON f.nekey = pb.nekey
WHERE p.nekey IS NULL
ORDER BY 1