TableDiff utility to compare data between two databases
Wednesday, July 18, 2012 |
Posted by
Ritesh Shah
0
comments
Labels:
Microsoft,
Ritesh Shah,
sql server 2008,
tablediff,
XP_CMDSHELL
MERGE statement in SQL Server 2008 and later version
Wednesday, June 29, 2011 |
Posted by
Ritesh Shah
http://www.sqlhub.com
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of http://www.SQLHub.com
0
comments
Labels:
Merge Statement,
Microsoft,
Ritesh Shah,
sql server 2008
Filtered Index in SQL Server 2008/Denali
Tuesday, June 21, 2011 |
Posted by
Ritesh Shah
http://www.sqlhub.com
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of http://www.SQLHub.com
0
comments
Labels:
index,
Microsoft,
Ritesh Shah,
sql server 2008
Create windows login and user in all databases with dataReader and dataWriter role in SQL Server 2008
Tuesday, March 16, 2010 |
Posted by
Ritesh Shah
CREATE PROC CreateWindowsLoginAndUser(@FullLoginName sysname, @ActionName sysname)
Once you are done with creating script, you can execute it by following commands.
--to create user, use following TSQL
Reference: Ritesh Shah
http://www.sqlhub.com
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of http://www.SQLHub.com
0
comments
Labels:
create login,
Microsoft,
Ritesh Shah,
sql server 2008,
T-sql
Update NULL records in all columns with any value which is NOT NULL in same column SQL Server 2005/2008
Wednesday, May 27, 2009 |
Posted by
Ritesh Shah
Today I gave solution for one strange problem in one of the forum; I thought to share that script with all of you. Requirement was something like below:
-- Update all field of Table which is NULL
--NULL data should be populated with NOT NULL value of the same column
Well, this is somehow strange but it was needed so I quickly create one small script with the help of cursor, however, I always avoid cursor as long as possible. I didn’t find any other quick solution at that time.
--create table for demo
if OBJECT_ID('emps','U') is not null drop table emps
CREATE TABLE [dbo].[emps](
[Name] [varchar](50) NULL,
[Dept] [varchar](10) NULL,
[Company] [varchar](15) NULL
) ON [PRIMARY]
GO
--insert some data
INSERT INTO emps
SELECT 'RITESH','MIS','CHEM' UNION ALL
SELECT 'RAJAN',NULL,NULL UNION ALL
SELECT NULL,'ACCT','MAR'
GO
--script with cursor
declare @SQL nvarchar(max)
DECLARE @ColName VARCHaR(15)
set @SQL=''
DECLARE FirstCur CURSOR FORWARD_ONLY
FOR select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='emps'
OPEN FirstCur
FETCH FROM FirstCur INTO @ColName
WHILE @@FETCH_STATUS=0
BEGIN
SET @SQL=@SQL+ ' Update Emps SET ' + @ColName + ' = (SELECT top 1 ' + @ColName + ' FROM emps where ' + @ColName + ' is not null) where ' + @ColName + ' is null; '
FETCH NEXT FROM FirstCur INTO @ColName
END
print @sql
CLOSE FirstCur
DEALLOCATE FirstCur
exec sp_executeSQL @SQL
go
--CHECK DATA
select * from emps
Happy Coding!!!!
Reference: Ritesh Shah
http://www.sqlhub.com
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of http://www.SQLHub.com
Latest Article in Extreme-Advice
Ask Me SQL Server question
Recent comment here
Comments for Ritesh's Blog for SQL-SERVER & .NET
Pages
About Me
- Ritesh Shah
- Ritesh Shah is a data professional with having 10+ years of experience in various domain of IT field. He is a author of many technical articles on Microsoft Technology and authored a book of SQL Server 2012 Performance Tuning. Apart from SQLHub, I used to share my knowledge at following places: http://blog.extreme-advice.com/ http://learn.extreme-advice.com/
Short Tips on Extreme-Exchange
Blog Roll
-
-
Reflections on 15 Years1 week ago
-
Data Quake7 years ago
-
test wrong solution9 years ago
-
Updateable columnstore index gotchas12 years ago
-
blog.extreme-advice.com is new blog home for me13 years ago
RSS
Feed
