lundi 5 novembre 2018

Inserting Random Names in as SQL values

So I created a database that is a bank with customers in it; but within that database I have written a function that returns 50 customers (or in my case, 50 John Smiths)

...Because I hardcoded the name John Smith, and his email address, of my customer within that code. Now I want to find a way to replace the name I hardcoded with a variable for first and last name that will return random names only. Like James Doe, Sally Fields etc...

Please point me to the right direction that would correctly replace the John Smiths with random names.

Here is the code of my function, so you get an idea on what I am talking about and what I am looking for.

BEGIN
     DECLARE @loopCount tinyint 
     DECLARE @tableCount tinyint
     DECLARE @randomSSN int
     SELECT @loopCount = 1
     WHILE (@loopCount <= 50)
        BEGIN
            SELECT @randomSSN = RAND()*(999999998)+1
            SELECT @tableCount = COUNT(*) FROM Customer WHERE SSN = @randomSSN
            IF @tableCount = 0
                 INSERT INTO Customer (FirstName, LastName, Email, SSN) VALUES ('John', 'Smith', 'JohnSmith@gmail.com', @randomSSN)
                SELECT @loopCount = @loopCount +1
        END
END




Aucun commentaire:

Enregistrer un commentaire