December 1, 2017 at 9:47 am
Hi ! i'm new in this forum so i say you hello asking help with a function ahah
I have to update my table "PERSONA" with a function that provides to change every "dfgfhgsf" with a real name in the "names" column and the same for every surname.
Furthermore this function should do the same with the fiscal code column in order to understand that the string in that column is still a fiscal code.
can anybody help me???
p.s. i'm trying like this
1 create a randomic name table
2 use this function to get randomized name
create FUNCTION GetRandomName()
RETURNS varchar(15)
AS
BEGIN
RETURN (
SELECT TOP 1 nome
FROM nomi --The table and column now have different names!
ORDER BY (SELECT [NewId] FROM GetNewID)
)
END
am i on the right way? thanks you!!!!!
December 1, 2017 at 3:46 pm
I just did this earlier today. I downloaded the most popular firstnames and lastnames from some website... so they're in their own tables. Then I did this (appended a partial cross join to a final table):
INSERT INTO Training.dbo.Technician (FirstName, Gender, LastName, StartDate, StoreID)
SELECT TOP 4000 f.FName
, f.Gender
, l.LName
, DATEADD(day,-1 * ABS(CHECKSUM(NEWID())%(15*365)),GETDATE()) AS StartDate -- a start date some random # of days ago
, ABS(CHECKSUM(NEWID())%100) AS StoreID
FROM Scratchpad.dbo.FirstNames f CROSS JOIN Scratchpad.dbo.LastNames l
ORDER BY NEWID();
The ORDER BY NEWID() basically randomizes the order, and then the TOP predicate just selects some of the results. It's pretty slow, but I only needed to run it once.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply