ASP.NET Session State SQL Server Mode provides a good way to have a persistent session, especially for server farm configuration. Here are the steps to quickly configure the environment to do so using SQL Server Express edition (because sometimes, you don't need the full-blown version of SQL Server just to track sessions). Steps Download and install SQL Server Express. Open the file, … [Read more...]
How to Show Field Values as Columns in SQL Server
One of the most asked questions by users when they pull data using T-SQL is whether or not there's a way to present the values of a field they're interested in as columns instead. The answer is of course it's "Yes." You can achieve this by using PIVOT relational operator if you use MSSQL 2005 or later. Without PIVOT With PIVOT Further Reading Using PIVOT and UNPIVOT SQL Server … [Read more...]
How to reset SA password on Microsoft SQL Server
If you happen to forget your sa password, you can still recover it as long as you have access to the server. Here are the steps to do it. Steps Launch Sql Configuration Manager under Configuration Tools folder. Look for your SQL Server instance (the default is MSSQLSERVER) and stop the service. You can click the stop button while having the SQL Server (MSSQLSERVER) row highlighted or you … [Read more...]
Ways to Upsert a Record in SQL Server
To continue the previous post, this article demonstrates ways to do Upsert (update and insert) and how MERGE statement in SQL Server 2008 (or later) can be more efficient to perform the two operations at once. First we'll create a table for this demo. We want to do update if the Id is found on the table and insert if it's a new Id number. 1. Conventional way of doing it is by using IF … [Read more...]
Perform Update, Delete and Insert using Merge Statement
In SQL Server, a better way to perform insert, update, or delete operations on a target table based on the results of a join with a source table is by using one MERGE statement. UPDELSERT using MERGE statement It's more efficient as you're doing just one statement instead of three individual (UPDATE, DELETE, and INSERT) SQL queries. More examples can be found on the next posting, Ways … [Read more...]