If Digits.d is declared as an integer, + will not concatenate.
"Joe Celko" <joe.celko@northface.edu> wrote in message
news:eO995tC5DHA.2580@TK2MSFTNGP11.phx.gbl...
> >> all possible ids in a format of AAA000 upto ZZZ999 into a table
> exceptions, idss starting with M can not be used,
> ids that are in the additional exception list can not be used either. <<
>
> That pattern is also used in the US.
>
> CREATE TABLE Digits
> (d INTEGER NOT NULL PRIMARY KEY
> CHECK (d BETWEEN 0 AND 9);
> -- insert zero to nine
>
> CREATE TABLE Alpha
> (a CHAR(1) NOT NULL PRIMARY KEY
> CHECK (a BETWEEN 'A' AND 'Z';
> --insert A thru Z
>
> CREATE TABLE ForbiddenList
> (bad_tag CHAR(6) NOT NULL PRIMARY KEY);
> --insert the bad tag numbers
>
> CREATE TABLE Tags
> (tag_nbr CHAR(6) NOT NULL PRIMARY KEY
> CHECK tag_nbr
> LIKE '[A-Z][A-Z][A-Z][0-9][0-9][0-9]'
> AND tat_nbr
> NOT LIKE 'M[A-Z][A-Z][0-9][0-9][0-9]');
>
> INSERT INTO Tags
> SELECT A1.a + A2.a + A3.a + D1.d + D2.d + D3.d
> FROM Alpha AS A1, Alpha AS A2, Alpha AS A3,
> Digits AS D1, Digits AS D2, Digits AS D3
> WHERE A1.a <> 'M'
> AND A1.a + A2.a + A3.a + D1.d + D2.d + D3.d
> NOT IN (SELECT bad_tag FROM ForbiddenList);
>
> If we had full SQL-92, then we could add a predicate to Tags that would
> handle the Forbidden tag list.
>
> >> select from the Tags table a random value <<
>
> This is not a relational operation, so it should be done in the front
> end. If you add a sequential number in a column to tags, so as to make
> this table into a sequential file (ugh!!), then you can use this:
>
> SELECT S1.*
> FROM Tags AS T1
> WHERE CEILING((SELECT COUNT(*) FROM Tags)
> * RAND())
> =(SELECT COUNT(*)
> FROM Tags AS T2
> WHERE T1.seq <= T2.seq);
>
> --CELKO--
> ===========================
> Please post DDL, so that people do not have to guess what the keys,
> constraints, Declarative Referential Integrity, datatypes, etc. in your
> schema are.
>
> *** Sent via Developersdex
http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!