October 8, 2012 at 5:38 am
Hi,
I need to write a SQL query to print the following aphanumberic sequence in SQL 2008.
0001, 0002, ... , 0009, 000A, ... , 000Z, ... , 0010, 0011, ... , 001A, ... and so on till... , ZZZZ
all characters should be in UPPERCASE.
Please Help me...
Thanks in advance
October 8, 2012 at 5:45 am
Forgive me if I'm mistaken, but all of your posts look like homework. What have you tried so far?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 8, 2012 at 5:49 am
Hi,
not exactly like home work, as per my requirement only am posting.
i've tried below code, but it is generating only number.
WITH Sequence ( SeqNo) as
(
SELECT 1
UNION ALL
SELECT SeqNo + 1
FROM Sequence
WHERE SeqNo < 1000
)
SELECT TOP 1000 * FROM Sequence
OPTION ( MAXRECURSION 0);
GO
please help me......
October 8, 2012 at 5:59 am
Use table constructor to generate your primary sequence, within a CTE. Then run a select from it, joined to itself 3 times (giving 4 references total in the FROM list). They can be CROSS JOINS or old fashioned comma joins. It works just fine. Have a try, post back if you are unsure.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 8, 2012 at 6:02 am
Below code is working in 'Oracle'
i need same output in sql.....
with digits as
( select n, chr(mod(n,36)+case when mod(n,36) < 10 then 48 else 55 end) d
from (Select rownum-1 as n from dual connect by level < 37)
)
select d0.n*36*36*36*36 + d1.n*36*36*36 + d2.n*36*36 + d3.n*36 + d4.n, d0.d||d1.d||d2.d||d3.d||d4.d
from digits d0,digits d1, digits d2, digits d3, digits d4
Plz
October 8, 2012 at 6:05 am
Skanda (10/8/2012)
Hi,not exactly like home work, as per my requirement only am posting.
i've tried below code, but it is generating only number.
WITH Sequence ( SeqNo) as
(
SELECT 1
UNION ALL
SELECT SeqNo + 1
FROM Sequence
WHERE SeqNo < 1000
)
SELECT TOP 1000 * FROM Sequence
OPTION ( MAXRECURSION 0);
GO
please help me......
You're looking at the top 1000 in your query, have you thought about how many rows there will actually be?
You have 36 characters in total for each digit (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z). So we're looking at 36*36*36*36 == 1,679,616 rows.
October 8, 2012 at 6:09 am
Skanda (10/8/2012)
Below code is working in 'Oracle'i need same output in sql.....
with digits as
( select n, chr(mod(n,36)+case when mod(n,36) < 10 then 48 else 55 end) d
from (Select rownum-1 as n from dual connect by level < 37)
)
select d0.n*36*36*36*36 + d1.n*36*36*36 + d2.n*36*36 + d3.n*36 + d4.n, d0.d||d1.d||d2.d||d3.d||d4.d
from digits d0,digits d1, digits d2, digits d3, digits d4
Plz
Chris covered how in his post, did you try it?
SELECT a.Chr+b.Chr+c.Chr+d.Chr
FROM (VALUES('0'),('1'),('2'),('3'),('4'),('5'),('6'),
('7'),('8'),('9'),('A'),('B'),('C'),('D'),
('E'),('F'),('G'),('H'),('I'),('J'),('K'),
('L'),('M'),('N'),('O'),('P'),('Q'),('R'),
('S'),('T'),('U'),('V'),('W'),('X'),('Y'),
('Z')
)a(Chr)
CROSS JOIN (VALUES('0'),('1'),('2'),('3'),('4'),('5'),('6'),
('7'),('8'),('9'),('A'),('B'),('C'),('D'),
('E'),('F'),('G'),('H'),('I'),('J'),('K'),
('L'),('M'),('N'),('O'),('P'),('Q'),('R'),
('S'),('T'),('U'),('V'),('W'),('X'),('Y'),
('Z')
)b(Chr)
CROSS JOIN (VALUES('0'),('1'),('2'),('3'),('4'),('5'),('6'),
('7'),('8'),('9'),('A'),('B'),('C'),('D'),
('E'),('F'),('G'),('H'),('I'),('J'),('K'),
('L'),('M'),('N'),('O'),('P'),('Q'),('R'),
('S'),('T'),('U'),('V'),('W'),('X'),('Y'),
('Z')
)c(Chr)
CROSS JOIN (VALUES('0'),('1'),('2'),('3'),('4'),('5'),('6'),
('7'),('8'),('9'),('A'),('B'),('C'),('D'),
('E'),('F'),('G'),('H'),('I'),('J'),('K'),
('L'),('M'),('N'),('O'),('P'),('Q'),('R'),
('S'),('T'),('U'),('V'),('W'),('X'),('Y'),
('Z')
)d(Chr)
ORDER BY a.Chr, b.Chr, c.Chr, d.Chr;
October 8, 2012 at 6:11 am
in query trying for 1000,
but i need max.
if it is more than 36*36*36*36, it helps me a lot...
October 8, 2012 at 6:16 am
Thank U Boss,
It is looking great...
but i need every record should have a numeric and alpabet,
in present code, some records are only alphabetic....
October 8, 2012 at 6:20 am
Skanda (10/8/2012)
Hi,I need to write a SQL query to print the following aphanumberic sequence in SQL 2008.
0001, 0002, ... , 0009, 000A, ... , 000Z, ... , 0010, 0011, ... , 001A, ... and so on till... , ZZZZ
all characters should be in UPPERCASE.
Please Help me...
Thanks in advance
Here's a TSQL equivalent of the Oracle CTE:
SELECT
n,
CHAR(n + CASE WHEN n < 10 THEN 48 ELSE 55 END)
FROM (SELECT TOP(36) n = ROW_NUMBER() OVER (ORDER BY (SELECT NULL))-1 FROM sys.columns a, sys.columns b) t
ORDER BY n
Can you figure it out from here?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 8, 2012 at 6:43 am
Skanda (10/8/2012)
Thank U Boss,It is looking great...
but i need every record should have a numeric and alpabet,
in present code, some records are only alphabetic....
In your original post, you said: -
Skanda (10/8/2012)
0001, 0002, ... , 0009, 000A, ... , 000Z, ... , 0010, 0011, ... , 001A, ... and so on till... , ZZZZ
"ZZZZ" doesn't have numeric values.
October 8, 2012 at 7:17 am
Cadavre (10/8/2012)
Skanda (10/8/2012)
Thank U Boss,It is looking great...
but i need every record should have a numeric and alpabet,
in present code, some records are only alphabetic....
In your original post, you said: -
Skanda (10/8/2012)
0001, 0002, ... , 0009, 000A, ... , 000Z, ... , 0010, 0011, ... , 001A, ... and so on till... , ZZZZ"ZZZZ" doesn't have numeric values.
And "0001, 0002, ... , 0009..." have no alpha characters...
I guess the method I've offered in the following thread might help you:
http://www.sqlservercentral.com/Forums/Topic1267659-391-1.aspx
October 27, 2012 at 11:43 pm
I wonder how many 3 and 4 letter swear words such a proccess will actually spell out.
I strongly recommend not using incrementing alpha-numerics for just such a reason but if you do, you really need to avoid the use of vowels at the very least.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 29, 2012 at 5:04 am
Jeff Moden (10/27/2012)
I wonder how many 3 and 4 letter swear words such a proccess will actually spell out...
Actually it depends how you take it, at least some of them will be easy to remember :-D.
By the way, English as a language is not very rich with such words in compare with some other languages (eg. world-champion in this business: Russian :hehe:)
October 29, 2012 at 6:22 am
Eugene Elutin (10/29/2012)
Jeff Moden (10/27/2012)
I wonder how many 3 and 4 letter swear words such a proccess will actually spell out...Actually it depends how you take it, at least some of them will be easy to remember :-D.
By the way, English as a language is not very rich with such words in compare with some other languages (eg. world-champion in this business: Russian :hehe:)
That's why we shouldn't be Russian to use incrementing Alpha-Numerics. 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 1 through 15 (of 26 total)
You must be logged in to reply to this topic. Login to reply