DECLARE @numberOfCountersNeeded as int;
DECLARE @newcounterval as bigint;
SET @numberOfCountersNeeded = 3
UPDATE c --get the counter interval and update the current count
SET @newcounterval = somefield = somefield + @numberOfCountersNeeded
FROM sometable c
WHERE conditions
Richard Golebiowski
No words wasted! Getting to the point about the work I do, the problems I deal with, and some links to posts about where I work.
Translate
Thursday, July 24, 2025
TSQL - Set A Variable While Updating
I needed to set the value in a variable and update a field at the same time This is the update query.
Friday, July 4, 2025
TSQL - Delete Duplicate Rows
This was the solution to a problem that was posted on Reddit. The OP asked how to delete a duplicate row. In the question, they just needed to delete a single duplicate. But then I wondered about cases where there was more than a single duplicate. In the example, EmployeeID is the primary key.
This is the finale SQL:
This is the finale SQL:
DECLARE @nC int; --number of records to delete
DECLARE @id int = 5; --key
SELECT @nc = count(*)-1 from [dbo].[TestTable]
WHERE EmployeeID = @id
DELETE top (@nc) from [dbo].[TestTable]
WHERE EmployeeID = @id
Monday, March 3, 2025
Salesforce - Error When Testing an Email in Flow
I was working on a flow in Salesforce and I was get an error in the email template. The error was: Error Occurred: We don't recognize the field prefix Opportunity. Associate a record that matches the prefix or update the template to remove the merge field from the body, subject, or letterhead. The error occured because I didn't have the Related Record ID set on the Send Email element.
Monday, October 21, 2024
Golang - Create Azure User
Function to ccreate a new user account in Azure using msgraph-sdk-go:
// creates a user in Azure with a minimal number of properties set
func CreateBaseAzureUser(strDisplayName, strMailNickName, strUserPrincipleName, strPassword, strEmployeeId string)(error){
logger.NLog.Info().Msg("CreateBaseAzureUser Started: dn: " + strDisplayName + " mnn: " + strMailNickName + " upn: " + strUserPrincipleName + " eid: " + strEmployeeId)
//employee id check: check if there is already a current user with the same employee id
//get the base azure user properties by employeeId
user, err := AzureGetBaseUsersByPropertyFilter("employeeId", strEmployeeId)
if user != nil {
if len(user.GetValue()) != 0 {
logger.NLog.Error().Err(err).Msg("CreateBaseAzureUser Error: " + strEmployeeId)
strM := "An Azure user with the employeeID " + strEmployeeId + " already exits."
utils.PostMessageT("it-help@internews.org", "Azure Account Creation Error for Emp. ID: " + strEmployeeId, strM)
return errors.New(strM)
}
}
requestBody := graphmodels.NewUser()
accountEnabled := true
// Enable the account
requestBody.SetAccountEnabled(&accountEnabled)
// Display Name
requestBody.SetDisplayName(&strDisplayName)
// Mail Nick Name
requestBody.SetMailNickname(&strMailNickName)
// User Principal Name
requestBody.SetUserPrincipalName(&strUserPrincipleName)
// Employee ID
requestBody.SetEmployeeId(&strEmployeeId)
// Password
passwordProfile := graphmodels.NewPasswordProfile()
forceChangePasswordNextSignIn := true
passwordProfile.SetForceChangePasswordNextSignIn(&forceChangePasswordNextSignIn)
passwordProfile.SetPassword(&strPassword)
requestBody.SetPasswordProfile(passwordProfile)
if azureGgraphConnector == nil{
err := InitializeAzureGraph()
if err != nil{
logger.NLog.Error().Err(err).Msg("CreateBaseAzureUser InitializeAzureGraph Error")
utils.PostMessageT("it-help@internews.org", "CreateBaseAzureUser InitializeAzureGraph Error for Emp. ID: " + strEmployeeId, err.Error())
return err
}
}
users, err := azureGgraphConnector.AppClient.Users().Post(context.Background(), requestBody, nil)
if err != nil {
logger.NLog.Error().Err(err).Msg("CreateBaseAzureUser error: " + strEmployeeId + " " + strDisplayName)
utils.PostMessageT("it-help@internews.org", "Azure Account Creation Error: " + strEmployeeId + " " + strDisplayName, err.Error())
return err
} else {
logger.NLog.Info().Msg("CreateBaseAzureUser user created: " + *users.GetDisplayName())
}
return nil
}
Friday, September 13, 2024
TSQL - Update Using A List of Values
I needed to update around 800 addresses from a list of addresses in a spreadsheet. I saved the spreadsheet as csv and then formated the csv fields into a list of values. Then I wrote an SQL select statement that took the list of values and made it into a subquery that I could join on the address table.
This is the finale SQL with just a subset of the values:
This is the finale SQL with just a subset of the values:
update aglA
set aglA.telephone = lh.phone
from address aglA
join (select * from (values('100000','1 707 822 4226'),('100010','1 707 826 9681'),('100030','1 707 445 8248'))as x( res_id, phone))lh on lh.res_id = aglA.res_id
Wednesday, February 28, 2024
Salesforce - Export Developer Console Query Results
After the query is run, rught click on the query results and select Inspect. Look for the table tag, and then click Copy and then Copy element. Paste the copied results into Excel.
Tuesday, December 19, 2023
Logitech C920 - Not Recognized by Windows 11
For me, the issue was caused by the USB ports. The webcam would not work on the USB hub that I was using with my laptop, a ThinkPad, and it would only work on certain ports on the ThinkPad USB-C Dock Gen 2.
Subscribe to:
Comments (Atom)
