Posted on October 29, 2009 by Raghunath Bhandari
How to create the row data as string.
If you have table row data and you need to show all the records in a single string, use the following query.
DATA:
——————–
Name
RAM
SHYAM
HARI
RITA
RESULT:
———————
Name
RAM,SHYAM,HARI,RITA
Use the following query
————————————
DECLARE @strList varchar(100)
SELECT @strList = COALESCE(@strList + ‘, ‘, ”) +
CAST(Name AS varchar(5))
FROM TABLE1
SELECT @strList
There are complex example in internet but you can [...]
Filed under: Table Row in String | Tagged: COALESCE, How to create a row data as string., MSSQL tisp, MSSQL tricks, Multiple value in single String, SQL help, String creation | 1 Comment »
Posted on January 23, 2009 by Raghunath Bhandari
How to use NULLIF (Transact-SQL)
NULLIF will Return a null value if the two specified expressions are equal. If you want to compare to fields and then this will work for you like :
Run these examples and you can see how to use it on your way.
Select NULLIF(‘aa’,'aa’)
Select isnull( NULLIF(‘aa’,'aa’),’right’)
MSDN is comparing NULLIF and CASE
To show [...]
Filed under: NULLIF (Transact-SQL) | Tagged: difference between nullif and case, MS SQL tricks, NULLIF (Transact-SQL), SQL help, SQL Tips, use of nullif | Leave a Comment »
Posted on January 14, 2009 by Raghunath Bhandari
Difference with (nolock) vs (nolock) as a SQL Table Hint:
select sum(amount) from reward_expired (nolock)
difference was between using the table hint (nolock) and the table hint with (nolock).
Look at MSDN under SQL 2005,
“In SQL Server 2005, with some exceptions, table hints are supported in the FROM clause only when the hints are specified with the WITH [...]
Filed under: with (nolock) vs (nolock) | Tagged: Difference with (nolock) vs (nolock), FASTFIRSTROW, Microsoft SQL server, MSSQL, MSSQL server, NOEXPAND, NOLOCK, NOWAIT, PAGLOCK, READCOMMITTED, READPAST, READUNCOMMITTED, REPEATABLEREAD, ROWLOCK, SERIALIZABLE, SQL help, SQL Server, SQL Tips, SQL Tricks, T-SQL best way, Table Hints, TABLOCK, TABLOCKX, UPDLOCK, with (nolock) vs (nolock), XLOCK | Leave a Comment »
Posted on December 31, 2008 by Raghunath Bhandari
SQL running serial generating tips:
Traditionally developers and Database administrators used temporary tables and co-related sub-queries to generate calculated row numbers in a query. Now SQL Server 2005 provides a function, which replaces all of the additional resources we used to generate row numbers.
Returns the sequential number of a row within a partition of a result [...]
Filed under: SQL ROW_NUMBER | Tagged: Generate Row number, Microsoft SQL server, MSSQL, MSSQL server, ROW_NUMBER(), SQL help, SQL ROW_NUMBER, SQL running serial, SQL running serial generating, SQL Server, SQL Tricks, sqlhelp, SQLtips | Leave a Comment »
Posted on December 26, 2008 by Raghunath Bhandari
Error Description ::
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)
Enable remote [...]
Filed under: SQL remote connection | Tagged: An error has occurred while establishing a connection to the server, connection SQL Server, Enable remote connection SQL Server, Microsoft SQL server, MSSQL, MSSQL server, problem in remote connection SQL Server, SQL help, SQL Server, SQL Tips, SQL Tricks | Leave a Comment »
Posted on December 24, 2008 by Raghunath Bhandari
Case sensitive comparisons in SQL Server
Some time we need to compare some data in binary see the examples:
SELECT * FROM TABLE1 WITH (NOLOCK) WHERE convert(varbinary(255), PASS) = convert(varbinary(255), ‘RAGHU’)
Normal comparison:
SELECT * FROM TABLE1 WITH (NOLOCK) WHERE convert(varbinary(255), PASS) = convert(varbinary(255), ‘Raghu’) AND PASS= ‘TEST’
Uuse the BINARY_CHECKSUM function:
SELECT * FROM TABLE1 WITH (NOLOCK) WHERE BINARY_CHECKSUM(answer) = [...]
Filed under: SQL String comparisons | Tagged: BINARY_CHECKSUM, Case sensitive comparisons in SQL, comparisons in SQL, Microsoft SQL server, MSSQL, MSSQL BINARY_CHECKSUM, MSSQL server, MSSQL string compare, MSSQL String comparisons tips, SQL best way to compare string, SQL help, SQL Server, SQL varbinary method | Leave a Comment »
Posted on December 19, 2008 by Raghunath Bhandari
BEGIN TRANSACTION represents a point at which the data referenced by a connection is logically and physically consistent. If errors are encountered, all data modifications made after the BEGIN TRANSACTION can be rolled back to return the data to this known state of consistency. Each transaction lasts until either it completes without errors and COMMIT [...]
Filed under: BEGIN TRANSACTION | Tagged: Author Raghunath Bhandari, BEGIN TRANSACTION, COMMIT TRANSACTION, Microsoft SQL server, MSSQL, MSSQL server, SQL help, SQL roll back, SQL Server, SQL Tips and Tricks | Leave a Comment »
Posted on December 14, 2008 by Raghunath Bhandari
SQL RAND Function
The SQL RAND() function is used to generate some random numbers at run time. Here is the syntax:
Syntax
RAND ( [ seed ] )
Repetitive calls of RAND() with the same seed value return the same results.
For one connection, if RAND() is called with a specified seed value, all subsequent calls of [...]
Filed under: SQL RAND Function | Tagged: Advance SQL tips and tricks, Database, Database Optimization Tips, dba, Introduction to SQL, Microsoft SQL server, MSSQL, MSSQL server, SQL, SQL Database Optimization Tricks, SQL help, SQL Optimization, SQL Optimization Tips, SQL Programming, SQL Query, SQL RAND Function, SQL Server, SQL server tips, SQL technology, SQL Tips, SQL Tips and Tricks, SQL tips for programmer, sqlhelp, T-SQL, what is SQL | Leave a Comment »
Posted on December 12, 2008 by Raghunath Bhandari
Introduction Bulk Insert:
The Bulk Insert task provides the quickest way to copy large amounts of data into a SQL Server table or view. For example, suppose your company stores its million-row product list on a mainframe system, but the company’s e-commerce system uses SQL Server 2005 to populate Web [...]
Filed under: Bulk Insert | Tagged: Advance SQL tips and tricks, BCP T-SQL, BCP Utility in SQL server, Bulk Insert, Bulk Insert in SQL, DBA help, How to use BCP in SQL, Microsoft SQL server, MSSQL, MSSQL server, SQL Database Settings Optimization Tips, SQL developer tips, SQL help, SQL Indexing Service, SQL Optimization, SQL Server, SQL server tips, SQL Tips, sqlhelp, upload CSV file in SQL, upload text file in SQL | Leave a Comment »
Posted on December 12, 2008 by Raghunath Bhandari
Introduction BCP Utility:
The bcp utility bulk copies data between an instance of Microsoft SQL Server 2005 and a data file in a user-specified format. The bcp utility can be used to import large numbers of new rows into SQL Server tables or to export data out of tables into [...]
Filed under: BCP Utility | Tagged: Advance SQL tips and tricks, BCP T-SQL, BCP Utility in SQL server, DBA help, How to use BCP in SQL, Microsoft SQL server, MSSQL, MSSQL server, SQL Database Settings Optimization Tips, SQL developer tips, SQL help, SQL Indexing Service, SQL Optimization, SQL Server, SQL server tips, SQL Tips, sqlhelp | Leave a Comment »
Posted on December 1, 2008 by Raghunath Bhandari
Tips And Tricks For Advanced MS SQL Server Developers:
Use “TRUNCATE TABLE” statement instead of “DELETE” clause if you want to delete all rows from a table. It is much faster then “DELETE” statement without any conditions. “TRUNCATE TABLE” frees all the space occupied by that table’s data and indexes, without logging [...]
Filed under: SQL Tricks | Tagged: Advance SQL tips and tricks, Author Raghunath Bhandari, Database, Database Optimization Tips, dba, DBA help, MCP, Microsoft Certified Professional, Microsoft SQL server, MSDN Help, MSDN SQL News, MSSQL, MSSQL server, SQL, SQL Database Optimization Tricks, SQL Database Settings Optimization Tips, SQL developer tips, SQL Documentation, SQL help, SQL Indexing Service, SQL Optimization, SQL Optimization Tips, SQL Query, SQL Server, SQL server tips, SQL technology, SQL Tips, SQL Tips and Tricks, SQL tips for programmer, sqlhelp, sqlhelp news, sqlhelp WebSite Review, T-SQL, Technology News, Tips And Tricks For Advanced MS SQL Server Developers | Leave a Comment »
Posted on December 1, 2008 by Raghunath Bhandari
Database Settings Optimization Tips
You can turn off the ‘auto create statistics’ database option.When this database option is set to true, statistics are automatically created on columns used in a predicate. By default, this database option is set to true. Because auto creation statistics results in some performance degradation, you can turn off this database option [...]
Filed under: Database Settings | Tagged: Advance SQL tips and tricks, Database Optimization Tips, Microsoft SQL server, MSSQL, MSSQL server, SQL Database Optimization Tricks, SQL Database Settings Optimization Tips, SQL help, SQL Optimization Tips, SQL Server, SQL server tips, SQL Tips, SQL tips for programmer, sqlhelp | Leave a Comment »
Posted on December 1, 2008 by Raghunath Bhandari
SQL Server Settings Optimization Tips:
You can increase the ‘min memory per query’ option to improve the performance of queries that use hashing or sorting operations, if your SQL Server has a lot of memory available and there are many queries running concurrently on the server.
The SQL Server will automatically allocate, at a minimum, the [...]
Filed under: SQL Optimization | Tagged: Advance SQL tips and tricks, Database Optimization Tips, Microsoft SQL server, MSSQL, MSSQL server, SQL Database Optimization Tricks, SQL Database Settings Optimization Tips, SQL help, SQL Optimization, SQL Optimization Tips, SQL Server, SQL server tips, SQL Tips, SQL tips for programmer, sqlhelp | 1 Comment »
Posted on November 30, 2008 by Raghunath Bhandari
Definition of a Database
A database is a collection of related information, accessed and managed by its DBMS. After experimenting with hierarchical and networked DBMSs during the 1970’s, the IT industry became dominated by relational DBMSs (Or Object-Relational Database Management System) such as Informix database, Oracle, Sybase, and, later on, Microsoft SQL Server and the like.
In [...]
Filed under: Basic Definitions | Tagged: Advance SQL tips and tricks, Database, Database Optimization Tips, dba, Microsoft SQL server, MSSQL, MSSQL server, SQL, SQL Basic Definitions, SQL Database Optimization Tricks, SQL Database Settings Optimization Tips, SQL Documentation, SQL help, SQL Optimization, SQL Optimization Tips, SQL Query, SQL Server, SQL server tips, SQL technology, SQL Tips, SQL Tips and Tricks, SQL tips for programmer, sqlhelp, T-SQL | Leave a Comment »
Posted on November 30, 2008 by Raghunath Bhandari
What is Indexing Service?
Indexing Service is a base service for Microsoft® Windows® 2000 or later that extracts content from files and constructs an indexed catalog to facilitate efficient and rapid searching.
Indexing Service can extract both text and property information from files on the local host and on remote, networked hosts. The files can be simply [...]
Filed under: Indexing Service | Tagged: Advance SQL tips and tricks, Author Raghunath Bhandari, Database, Database Optimization Tips, dba, MCP, Microsoft Certified Professional, Microsoft SQL server, MSDN Help, MSDN SQL News, MSSQL, MSSQL server, SQL, SQL Database Optimization Tricks, SQL Database Settings Optimization Tips, SQL Documentation, SQL help, SQL Indexing Service, SQL Optimization, SQL Optimization Tips, SQL Query, SQL Server, SQL server tips, SQL technology, SQL Tips, SQL Tips and Tricks, SQL tips for programmer, sqlhelp, sqlhelp news, sqlhelp WebSite Review, T-SQL, Technology News | Leave a Comment »
Posted on November 28, 2008 by Raghunath Bhandari
SQL Performance Tuning using Indexes
This article looks at general guidelines to creating effective indexes using short keys, distinct keys, covering indexes and clustered indexes.
Effective indexes are one of the best ways to improve performance in a database application. Without an index, the SQL Server engine is like a reader trying to find a word in [...]
Filed under: SQL Performance | Tagged: Advance SQL tips and tricks, Author Raghunath Bhandari, Database, Database Optimization Tips, dba, MCP, Microsoft Certified Professional, Microsoft SQL server, MSDN Help, MSDN SQL News, MSSQL, MSSQL server, SQL, SQL Database Optimization Tricks, SQL Database Settings Optimization Tips, SQL Documentation, SQL help, SQL Optimization, SQL Optimization Tips, SQL Performance Tuning using Indexes, SQL Query, SQL Server, SQL server tips, SQL technology, SQL Tips, SQL Tips and Tricks, SQL tips for programmer, sqlhelp, sqlhelp news, sqlhelp WebSite Review, T-SQL, Technology News | Leave a Comment »
Posted on November 28, 2008 by Raghunath Bhandari
CREATE PARTITION FUNCTION (Transact-SQL)
Creates a function in the current database that maps the rows of a table or index into partitions based on the values of a specified column. Using CREATE PARTITION FUNCTION is the first step in creating a partitioned table or index.
Syntax
CREATE PARTITION FUNCTION partition_function_name ( input_parameter_type )
AS RANGE [ LEFT | RIGHT [...]
Filed under: Partitioning a Table | Tagged: Advance SQL tips and tricks, Author Raghunath Bhandari, Database, Database Optimization Tips, dba, MCP, Microsoft Certified Professional, Microsoft SQL server, MSDN Help, MSDN SQL News, MSSQL, MSSQL server, PARTITION, SQL, SQL Database Optimization Tricks, SQL Database Settings Optimization Tips, SQL Documentation, SQL help, SQL Optimization, SQL Optimization Tips, SQL Query, SQL Server, SQL server tips, SQL technology, SQL Tips, SQL Tips and Tricks, SQL tips for programmer, sqlhelp, sqlhelp news, sqlhelp WebSite Review, T-SQL, Technology News | Leave a Comment »
Posted on November 28, 2008 by Raghunath Bhandari
Is it ever good database design practice (for speed sake, etc.) to essentially make copies of tables to hold a certain group of data?
For example, I have come across a database table that stores information for a housing subdivision; ie. lot number, lot size, lot price, etc. And the database to which this table belongs [...]
Filed under: Partitioning a Table | Tagged: Advance SQL tips and tricks, Author Raghunath Bhandari, Database, Database Optimization Tips, dba, MCP, Microsoft Certified Professional, Microsoft SQL server, MSDN Help, MSDN SQL News, MSSQL, MSSQL server, Partitioning, SQL, SQL Database Optimization Tricks, SQL Database Settings Optimization Tips, SQL Documentation, SQL help, SQL Optimization, SQL Optimization Tips, SQL Query, SQL Server, SQL server tips, SQL technology, SQL Tips, SQL Tips and Tricks, SQL tips for programmer, sqlhelp, sqlhelp news, sqlhelp WebSite Review, T-SQL, Technology News | Leave a Comment »
Posted on November 23, 2008 by Raghunath Bhandari
Backup/Restore Optimization Tips:
Try to perform backup to the local hard disk first, and copy backup file(s) to the tape later.
When you perform backup, some SQL Server commands cannot be made, for example: during backup you cannot run ALTER DATABASE statement with either the ADD FILE or REMOVE FILE options, you cannot shrink database, you cannot [...]
Filed under: Backup/Restore Tips | Tagged: Advance SQL tips and tricks, Author Raghunath Bhandari, Database, Database Optimization Tips, dba, MCP, Microsoft Certified Professional, Microsoft SQL server, MSDN Help, MSDN SQL News, MSSQL, MSSQL Resources, MSSQL server, MSSQL Server help, SQL, SQL Backup/Restore, SQL Best practices and tips, SQL Coding Standards, SQL Database Optimization Tricks, SQL Database Settings Optimization Tips, SQL Documentation, SQL help, SQL Optimization, SQL Optimization Tips, SQL Query, SQL Server, SQL server tips, SQL technology, SQL Tips, SQL Tips and Tricks, SQL tips for programmer, sqlhelp, sqlhelp news, sqlhelp WebSite Review, T-SQL, Technology News | Leave a Comment »
Posted on November 5, 2008 by Raghunath Bhandari
Analyze and Fix Index Fragmentation in SQL Server 2008
It is very common that over time SQL Server tables and indexes tend to become fragmented. The fragmentation generally happens when data within the underlying tables on which an index exists is modified. The data modification basically can be an insert, update or a delete operation. The [...]
Filed under: Fragmentation in SQL, SQL Performance | Tagged: Advance SQL tips and tricks, Author Raghunath Bhandari, Database, Database Optimization Tips, dba, MCP, Microsoft Certified Professional, Microsoft SQL server, MSDN Help, MSDN SQL News, MSSQL, MSSQL Resources, MSSQL server, MSSQL Server help, SQL, SQL Best practices and tips, SQL Coding Standards, SQL Database Optimization Tricks, SQL Database Settings Optimization Tips, SQL Documentation, SQL Fragmentation, SQL help, SQL Optimization, SQL Optimization Tips, SQL Query, SQL Server, SQL server tips, SQL technology, SQL Tips, SQL Tips and Tricks, SQL tips for programmer, sqlhelp, sqlhelp news, sqlhelp WebSite Review, T-SQL, Technology News | Leave a Comment »