![]() We can use the following code to generate some random strings: So if we have a !! def', then we may have strings like 'abc 12 def' or 'abc 87 def' generated.įor canadian post code the pattern can be !' (the middle blank space will be kept as it is in the generated string, like 'V1A 2P5'Ĭreate function dbo.ucf_random_pattern nvarchar(max), int=0 )Įxternal name. Returns nvarchar(max) with execute as callerĮxternal name means one letter from a to z (both lower and upper cases), ! means one digit number, i.e. Use MSSQLTips - this is my test databaseĪlter database MSSQLTips set trustworthy on įrom 'C:\mssqltips\Random_String\bin\CLR_Rand_String.dll'Ĭreate function dbo.ucf_random_string int, int, int =0) In my case, after I build the application to generate a DLL file, which I put it under c:\MSSQLTips\Random_String\bin\ folder, I need to run the following to import the DLL into SQL Server 2012. StringBuilder sb = new StringBuilder(pattern.Length) String CharList = "abcdefghijklmnopqrstvvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" Public static SqlString fn_random_pattern(SqlString pat, SqlInt32 seed) Using (var rng = new RNGCryptoServiceProvider()) Public static SqlString fn_random_string(SqlInt32 minLen, SqlInt32 maxLen, SqlInt32 seed) ![]() Public partial class UserDefinedFunctions I will not repeat the steps about how to create/deploy an assembly with Visual Studio, but you can refer to the links in section to find the details.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |