Just a short SQL script which will allow you to find the mutiple rows with the same values in the same table. I am not going to explain what the query does since its a very straight forward query
SQL:
SELECT [column_name]
FROM [tablename]
GROUP BY [column_name]
HAVING count(*)> 1
— OR
SELECT * FROM [TableName] WHERE [ColumnName] IN (
SELECT [ColumnName] FROM (
SELECT count([ColumnName]) AS N, [ColumnName] FROM [TableName]
—Where Clause If needed
GROUP BY [ColumnName]
)a
WHERE N> 1
)
There is a similar article which describes more techniques to follow for managing duplicate rows from a table .
http://support.microsoft.com/kb/139444
Sphere: Related Content
No Comments »
I sure lot of people might want to use the script where they would want to loop over multiple databases sitting on a Single server. In my case, I had to check for a Login Record in all the databases since the person left the company and we wanted to disable his/her access. SO I wrote simple CURSOR script in MSSQL 2000. Hope this help to someone.
SQL:
USE master
DECLARE db_names CURSOR FOR
SELECT name FROM sysdatabases
—Where Clause, Enable if you want to filter out some databases.
—where name like ‘databaseIwantName_%’ and name not like ‘databaseIdontwantName’
DECLARE @db_name varchar(100)
DECLARE @QueryString NVARCHAR(500)
DECLARE @UpdateString NVARCHAR(500)
OPEN db_names
FETCH NEXT FROM db_names INTO
@db_name
WHILE @@FETCH_STATUS = 0
BEGIN
—PRINT @db_nam
—In My case I used tbl_logins to do multiple select .
SET @QueryString = ‘Select * from ‘ + @db_name + ‘..logins where login like ‘‘%loginname%’’ ‘
EXEC sp_executesql @QueryString
IF @@RowCount> 0
BEGIN
—This gives the database name if there are any record found with the select state ran above
PRINT @db_name
END
—Similarly you can also have any Insert/Update Query IN a Loop.See example below
—In My case I used tbl_logins to do multiple Update At Once.
—SET @UpdateString = ‘update ’ + @db_name + ‘..tbllogins set password = ‘’account_blocked_out’‘, security_level = 0, approved = 0 where login like ‘’%loginname%’‘’
—PRINT @UpdateString
—EXEC sp_executesql @UpdateString
FETCH NEXT FROM db_names INTO
@db_name
END
CLOSE db_names
DEALLOCATE db_names
This is something written quick. Here is the Code for your Download. I am sure you can tune it better and if you do, please let me know . I would love to see your Ideas.
Thanks
Sphere: Related Content
No Comments »
I have been looking so much for this error in Coldfusion MX but could not find any solution to my problem. null null is a very vague exception error which gets thrown once in a while. Below are the steps I did to troubleshoot and one of them did the solved the problem.
1) Apply this hot fix from Adobe.
2) Increase the JVM Heap Size. (I increased it from 512 to 800)
3) Make sure your SELECT query does not pass any corrupt data. It might also be the very cause to throw the exception error.Turning off query caching signifigantly increased the number of errors, so it seems to be something in the JDBC drivers.
4) Check to see if you have methods that accept parameters passed by reference(like getimagesize()) . Make sure you use right script language for example getimagesize uses VBSCRIPT not JSCRIPT. ( For me this was the case. I removed this method and it stopped the error completely).
Sphere: Related Content
1 Comment »