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

  • SEARCH
  • Home
  • 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 6695613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:14:34+00:00 2026-05-26T06:14:34+00:00

Ok first the query I will be displaying is very rough looking. Pointers on

  • 0

Ok first the query I will be displaying is very rough looking. Pointers on how to optimize it would be great but that is not my main purpose right now I need something that works. I will post the query and the results

    SELECT u.[UserName]
      ,u.[LoweredUserName]
      ,m.[BarCode]
      ,m.[MemberID]
      ,d.[FirstName]
      ,d.[LastName]
  FROM [sqlmdstgbiz02].[WebDB].[dbo].[aspnet_Users] u,
  [mdsqlst].[CMS_PRODUCTION].[dbo].[memMember] me,
  [mdsqlst].[CMS_PRODUCTION].[dbo].[Demographics] d,
  [sqlmd05stg\sqlmd05stg].EntranceControl.dbo.MemberBarCodes m
  where
  (substring(u.UserName, len(u.UserName)-12,13) = m.Barcode or
  substring(u.UserName, len(u.UserName)-11,12)  = m.Barcode or
  substring(u.UserName, len(u.UserName)-10,11)  = m.Barcode or
  substring(u.UserName, len(u.UserName)-9,10)  = m.Barcode or
  substring(u.UserName, len(u.UserName)-8,9) = m.Barcode) and
  me.MemberID = m.MemberID and me.DemographicsID = d.DemographicsID

The results of the code are

UserName          BarCode        MemberID      FirstName   LastName
down120000008     120000008      8300100364005 TOUCH       DOWN
test120000009     120000009      8300100606009 KET TAG     TEST
abbott123567567   123567567      8300100635008 HENRY       ABBOTT

Now as you can see the UserName is simple the Lastname and the BarCode combined together. What I need to do is update the UserName with the LastName and MemberID but in a way that will allow me to update hundreds of UserName with one script. All of this information is on different servers so I know I have to do a Linked Server which the DBA is setting up right now. Any more information please ask.

  • 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-26T06:14:34+00:00Added an answer on May 26, 2026 at 6:14 am

    Assuming this is SQL Server, you can use UPDATE FROM to perform the update.

     BEGIN TRAN
    
     UPDATE u 
     SET    UserName = d.FirstName + m.MemberID
     OUTPUT INSERTED.*
     FROM   [sqlmdstgbiz02].[WebDB].[dbo].[aspnet_Users] u
            , [mdsqlst].[CMS_PRODUCTION].[dbo].[memMember] me
            , [mdsqlst].[CMS_PRODUCTION].[dbo].[Demographics] d
            , [sqlmd05stg\sqlmd05stg].EntranceControl.dbo.MemberBarCodes m
     WHERE  (substring(u.UserName, len(u.UserName)-12,13) = m.Barcode 
              or substring(u.UserName, len(u.UserName)-11,12)  = m.Barcode 
              or substring(u.UserName, len(u.UserName)-10,11)  = m.Barcode 
              or substring(u.UserName, len(u.UserName)-9,10)  = m.Barcode 
              or substring(u.UserName, len(u.UserName)-8,9) = m.Barcode
            ) 
            and me.MemberID = m.MemberID 
            and me.DemographicsID = d.DemographicsID
    
     ROLLBACK TRAN
    

    Edit

    As HLGEM correctly points out, you should replace the implicit syntax with proper INNER JOIN statements.

     BEGIN TRAN
    
     UPDATE u
     SET    UserName = d.FirstName + m.MemberID
     OUTPUT INSERTED.*
     FROM   [mdsqlst].[CMS_PRODUCTION].[dbo].[memMember] me
            INNER JOIN [mdsqlst].[CMS_PRODUCTION].[dbo].[Demographics] d ON d.DemographicsID = me.DemographicsID
            INNER JOIN [sqlmd05stg\sqlmd05stg].EntranceControl.dbo.MemberBarCodes m ON m.MemberID = me.MemberID
            INNER JOIN [sqlmdstgbiz02].[WebDB].[dbo].[aspnet_Users] u ON u.UserName LIKE '%' + m.Barcode
    
     ROLLBACK TRAN
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, from BOL : Queries that modify table variables do not generate parallel query
The first thing i would like to say is that this is not exactly
With :limit in query, I will get first N records. What is the easiest
I'm running a query that is timing out for first two times and returning
I can't display the first entry from my query that returns multiple answers. For
I'm trying to set up a query that shows the first post of each
With the first query in the following code I am looking for the checkings
On a site that I'm working on, I'm displaying results from a database query.
A bit of background first: GeoModel is a library I wrote that adds very
Given the following selector $('parent > child'), I believe jQuery will first query for

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.