Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Gekko
Yak Posting Veteran
63 Posts |
Posted - 2011-07-26 : 09:44:59
|
hallo .....I am sorry, code = NVARCHAR(3)how to make select the missing numbers from 1 to 999?exampl.(from 1 to 10)TabProductscode1345810result to grid:2679select ..... ???thanks |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-07-26 : 09:58:38
|
[code];WITH n(n) AS (SELECT 0 UNION ALL SELECT 0 UNION ALL SELECT 0),a(a) AS (SELECT 0 FROM n a CROSS JOIN n b CROSS JOIN n c),b(b) AS (SELECT 0 FROM a CROSS JOIN a b CROSS JOIN a c),r(r) AS (SELECT ROW_NUMBER() OVER (ORDER BY b) FROM b) -- generate all numbers from 1 to 1000SELECT * FROM r WHERE r<=1000AND NOT EXISTS(SELECT * FROM TabProducts WHERE code=r.r)[/code] |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-07-26 : 10:03:54
|
declare @sample table(seq int)insert @sampleselect 1 union allselect 2 union allselect 5 union allselect 8select n.numberfrom (select number from master..spt_values where type = 'p' and number between 1 and 10) nleft join @sample son n.number = s.seqwhere s.seq is null No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
Gekko
Yak Posting Veteran
63 Posts |
Posted - 2011-07-26 : 10:08:12
|
r(r) AS (SELECT ROW_NUMBER() OVER (ORDER BY b) FROM b)oups....code is NVARCHAR(3) Is it big problem?mess:Error converting data type nvarchar to bigint. |
 |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-07-27 : 09:32:39
|
If the code contains non-numeric characters, then yes. |
 |
|
|
|
|