![]() I see this as a problem, since changing the order of evaluation produces different results. In this case, each reference to R1 gets expanded into the expression that contains the NEWID() and consequently NEWID() gets called 8 times.But of course, any change (like Michael's TOP 100 PERCENT) might change the plan such that it stops working.Īnd I tested yours unchanged query on 2005 and its a no go - The Heisenberg uncertainty principle also applies when debugging Because SQL Server typically treats scalar operations as cheap, it tends to produce query plans that reevaluate things that one might expect to be evaluated once earlier in the plan. The fact that it does work, as Michael says, relies on when the NEWID() gets evaluated. At least, it does when I run it on my SQL Server 2000 installation. Ok im confused, why would your code ever work Arnold, or are you kidding and I just to slow? Ok im confused, why would your code ever work Arnold, or are you kidding and I just to slow? - The Heisenberg uncertainty principle also applies when debugging declare varchar(200)declare = 100 percent NUMBER, R1 = abs(convert(bigint,convert(varbinary(100),newid())))FROM - Function available in Script Library Forumğ_TABLE_NUMBER_RANGE(1,5) aaa) aaResults: password - YYYYYYYYQQQQQQQQIIIIIIII22222222FFFFFFFF(5 row(s) affected) CODO ERGO SUM I wasn't sure if there is a order of evaluation I could depend on, so I did it with multiple columns. For example, the following code will return a string of the same 8 characters. That actually depends on when SQL Server decides to evaluate the newid() function. Sequal to Password Generation Challenge ? Michael, why does your aa subquery have columns R1 to R8?This will work just as well: declare varchar(200)declare = abs(convert(bigint,convert(varbinary(100),newid())))FROM - Function available in Script Library Forumğ_TABLE_NUMBER_RANGE(1,100) aaa) aa declare varchar(200)declare = abs(convert(bigint,convert(varbinary(100),newid()))), R2 = abs(convert(bigint,convert(varbinary(100),newid()))), R3 = abs(convert(bigint,convert(varbinary(100),newid()))), R4 = abs(convert(bigint,convert(varbinary(100),newid()))), R5 = abs(convert(bigint,convert(varbinary(100),newid()))), R6 = abs(convert(bigint,convert(varbinary(100),newid()))), R7 = abs(convert(bigint,convert(varbinary(100),newid()))), R8 = abs(convert(bigint,convert(varbinary(100),newid())))FROM - Function available in Script Library Forumğ_TABLE_NUMBER_RANGE(1,100) aaa) aa CODO ERGO SUM ![]() The code shown will return 100 passwords. ![]() ![]() ![]() Here is a set based method that can be used to generate as many random 8 character passwords as you want. Hi GuysI used this - hope it helps!to call it simply use (example returns six char password):select dbo.fGeneratePassword(6,newid()) create function uniqueidentifier) returns varchar(255) as begin declare varchar(255) set = would generate a very weak password with only 16,777,216 possible combinations. Hi GuysI used this - hope it helps!to call it simply use (example returns six char password):select dbo.fGeneratePassword(6,newid()) create function uniqueidentifier) returns varchar(255) as begin declare varchar(255) set = Valentine Jones All ForumsĮvening Folks!I'm trying to create what will eventually be a UDF to generate a random 8-character string of mixed case, alpha-numeric characters.Here's what I've got so far:declare varchar(100)declare intdeclare intdeclare varchar(8)set = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'set = 1while 15 THEN 15 ELSE END DECLARE varchar(100)ĝECLARE intĝECLARE floatĝECLARE intĝECLARE varchar(15) SET = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' SET = 1 SET = '' WHILE <= SET = + 1 SET = (SELECT random from vw_random) SET = SET = + 1)ĞND RETURN again everyone!Bob We've got lots of great SQL ServerĮxperts to answer whatever question you can come up with. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |