Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6961079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:29:05+00:00 2026-05-27T15:29:05+00:00

I trying to make a sql script that will randomize the city, state, and

  • 0

I trying to make a sql script that will randomize the city, state, and zip code of a “members” table. I have made a table function that returns a single row with columns “city”, “state” and “zip” taken from another database at random (via a view). This ensures that I get a city, state, and zip that actually correlate to each other in the real world.

From there I am trying to do something like this:

update t
set 
t.City = citystate.city,
t.State = citystate.state,
t.PostalCode = citystate.zip

from
(select
 City, 
 State,
 PostalCode from DATABASE.dbo.Member) t,
 DATABASE.dbo.getRandomCityState() citystate

Problem is, this only calls my function once, and puts the same city, state, and zip into every row of the table. Is there some way to call my function once for every row in the table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:29:06+00:00Added an answer on May 27, 2026 at 3:29 pm

    Ok so thanks to one of my co-workers, we found a solution. It would seem that since the function didn’t take any parameters, SQL Server decided that the result would never change. So we tricked the server into thinking it will be different every time by passing a parameter to the function that was different: the id of each row. Since we were passing a different parameter each time, it called the function for every row.

    update t 
    set 
    t.City = citystate.city,
    t.State = citystate.state,
    t.PostalCode = citystate.zip
    
    from
    (select top 10 
    City, 
     State,
     PostalCode from TrajectoryServicesTest.dbo.Member) t
     cross apply SanitizePhi.dbo.getRandomCityState(t.MemberID) citystate
    

    Kinda hacky, but it worked. Thanks to Joe for the help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a stored procedure in SQL that will : Make a
I have made a script that run various loops and does some SQL inserts.
I have seen majority of web programmers (writing some script with sql to make
I have some SQL scripts that I'm trying to automate. In the past I
I'm trying to run a sql script using H2's runscript. One of the table
I am trying to develop an ANT script that calls SQL*Plus and executes a
I am trying to make our SQL Server Integration Services packages as portable as
Trying to make a generic PL/SQL procedure to export data in specific XML format,
Trying to make a MySQL-based application support MS SQL, I ran into the following
I'm trying to make a connection to a SQL Server Express DB on localhost,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.