Click here to Skip to main content
15,922,427 members
Home / Discussions / Database
   

Database

 
GeneralRe: remove commas in a column in mssql Pin
Blue_Boy28-Aug-08 5:06
Blue_Boy28-Aug-08 5:06 
QuestionHow to use a string variable in SQL query string? Pin
chenayang27-Aug-08 18:43
chenayang27-Aug-08 18:43 
AnswerRe: How to use a string variable in SQL query string? Pin
N a v a n e e t h27-Aug-08 19:33
N a v a n e e t h27-Aug-08 19:33 
GeneralRe: How to use a string variable in SQL query string? Pin
chenayang27-Aug-08 23:42
chenayang27-Aug-08 23:42 
QuestionProblem with SQL Query doing inner joins [modified] Pin
Sunset Towers27-Aug-08 14:23
Sunset Towers27-Aug-08 14:23 
AnswerRe: Problem with SQL Query doing inner joins Pin
PIEBALDconsult27-Aug-08 16:09
mvePIEBALDconsult27-Aug-08 16:09 
GeneralRe: Problem with SQL Query doing inner joins Pin
Sunset Towers27-Aug-08 16:14
Sunset Towers27-Aug-08 16:14 
QuestionInput requested on SQL Random String Generator Pin
Jesse Wimberley27-Aug-08 13:47
Jesse Wimberley27-Aug-08 13:47 
I created a Stored Procedure to create random strings of the length and complexity desired. It is based on the widely published spt_values query for near random numbers.

It is functional, but I'm not entirely happy with the script. There has to be more elegant way to handle different complexity settings, other than the IF...ELSE clauses I used.

CODE:
<br />
-- Random String Generator<br />
-- By: Jesse Wimberley<br />
-- 27 August 2008<br />
-- Description: Creates Random strings of <br />
-- variable length and complexity.<br />
CREATE PROCEDURE [dbo].[up_RanGen]<br />
@Return varchar(200) = '' OUTPUT,<br />
-- @Len for the length of the output<br />
@Len int = 8,<br />
--Complexity set with @Complex<br />
-- 1 = Uppercase Letters<br />
-- 2 = Uppercase and Lowercase Letters<br />
-- 3 = Uppercase, Lowercase and Numbers<br />
-- 4 = Complex Password<br />
@Complex int = 4<br />
AS<br />
BEGIN<br />
	SET NOCOUNT ON;<br />
declare @Random varchar(200)<br />
-- @a thru @f set the ranges of acceptable values for each character<br />
declare @a int, @b int, @c int, @d int, @e int, @f int<br />
If @Complex = 1<br />
BEGIN<br />
set @a = 65<br />
set @b = 80<br />
set @c = 81<br />
set @d = 82<br />
set @e = 83<br />
set @f = 90<br />
END<br />
ELSE<br />
If @Complex = 2<br />
BEGIN<br />
set @a = 65<br />
set @b = 90<br />
set @c = 97<br />
set @d = 100<br />
set @e = 101<br />
set @f = 122<br />
END<br />
ELSE<br />
If @Complex = 3<br />
BEGIN<br />
set @a = 65<br />
set @b = 90<br />
set @c = 97<br />
set @d = 122<br />
set @e = 48<br />
set @f = 57<br />
END<br />
ELSE<br />
BEGIN<br />
set @a = 48<br />
set @b = 60<br />
set @c = 61<br />
set @d = 75<br />
set @e = 76<br />
set @f = 122<br />
END<br />
set @Random=''<br />
select @Random=@Random+char(n) from<br />
(<br />
	select top (@Len) number as n from master.dbo.spt_values <br />
	where (type='p' and number between (@a) and (@b)) or (type='p' and number between (@c) and (@d)) or (type='p' and number between (@e) and (@f))<br />
	order by newid()<br />
) as t<br />
set @Return = @Random<br />
END<br />


The four complexity settings are based on ranges of values returned as their ascii equivalents. Upper/Lower/Numbers has three ranges of numbers. For simplicity, I stretched all four settings across three ranges, even when only one or two ranges were needed.
Questionbetween max() and min() Pin
nelsonpaixao27-Aug-08 13:33
nelsonpaixao27-Aug-08 13:33 
AnswerRe: between max() and min() Pin
TheFM23427-Aug-08 13:52
TheFM23427-Aug-08 13:52 
AnswerRe: between max() and min() Pin
Blue_Boy27-Aug-08 21:02
Blue_Boy27-Aug-08 21:02 
AnswerRe: between max() and min() Pin
MatthysDT28-Aug-08 1:34
MatthysDT28-Aug-08 1:34 
Questionarray Pin
nelsonpaixao27-Aug-08 13:09
nelsonpaixao27-Aug-08 13:09 
AnswerRe: array Pin
Ashfield27-Aug-08 20:57
Ashfield27-Aug-08 20:57 
AnswerRe: array Pin
MatthysDT28-Aug-08 1:56
MatthysDT28-Aug-08 1:56 
Questiontable Pin
nelsonpaixao27-Aug-08 13:02
nelsonpaixao27-Aug-08 13:02 
AnswerRe: table Pin
Ashfield27-Aug-08 20:50
Ashfield27-Aug-08 20:50 
AnswerRe: table Pin
TheFM23428-Aug-08 16:54
TheFM23428-Aug-08 16:54 
QuestionGrouping by most recent date Pin
Netblue27-Aug-08 8:21
Netblue27-Aug-08 8:21 
AnswerRe: Grouping by most recent date Pin
Ashfield27-Aug-08 8:57
Ashfield27-Aug-08 8:57 
GeneralRe: Grouping by most recent date Pin
Netblue27-Aug-08 9:07
Netblue27-Aug-08 9:07 
GeneralRe: Grouping by most recent date Pin
Ashfield27-Aug-08 21:53
Ashfield27-Aug-08 21:53 
Questionhow to find string existence in the another string . Pin
lakshmichawala27-Aug-08 2:32
lakshmichawala27-Aug-08 2:32 
AnswerRe: how to find string existence in the another string . Pin
Ashfield27-Aug-08 2:37
Ashfield27-Aug-08 2:37 
GeneralRe: how to find string existence in the another string . Pin
lakshmichawala27-Aug-08 2:54
lakshmichawala27-Aug-08 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.