SQL Server – Saving Changes Not Permitted in Management Studio
SQL Server Management Studio does not allow you to save changes to a table which require table re-creation such as changing data type for a column. When you perform such changes you will run into...
View ArticleSQL Server – Add Date/Time to output file of BCP / SQLCMD
You can export data from SQL Server using BCP command for SQLCMD utility. However, these utilities does not support dynamic file names when exporting data. For generating dynamic file names you can use...
View ArticleSQL Server – Add Date/Time to output file of BCP / SQLCMD (2)
Last time I posted about How you can add date/time to output file name, in which I used xp_cmdshell to execute the BCP/SQLCMD command using TSQL, which means we need to have xp_cmdshell server feature...
View ArticleSQL Server – Import Data from Excel using T-SQL
To import data from an Excel file to SQL Server you can use SQL Server Import and Export Wizard. You can also import Excel data using T-SQL OPENROWSET function. OPENROWSET function can be used to...
View ArticleSQL Server – How to Move Table to Another Schema
Starting with SQL Server 2005 all tables are grouped into schemas. While creating a table if the schema name is not specified it is created in the default schema of the user creating it. you can use...
View ArticleSQL Server – Update Table with INNER JOIN
Often we may need to update a column in a table based of another column in another table. In SQL Server you can do this using UPDATE statement by joining tables together. To understand this better...
View ArticleSQL Server – SELECTing/Displaying Top N rows from a table
To SELECT only top N rows from a table we can use TOP clause in SELECT statement. Using TOP clause we can also specify percentage option. For example, both of these statements are valid: USE SqlAndMe...
View ArticleSQL Server – Import text file using xp_cmdshell
There are several options available to import data from external sources to SQL Server. Such as Import & Export Wizard, BULK INSERT command, SSIS and OPENROWSET. Apart from this options you can...
View ArticleSQL Server – Custom sorting in ORDER BY clause
ORDER BY clause can be used to sort the results returned by SELECT statement in SQL Server. It orders the result set by specified column list. When used with character data type columns it sorts data...
View ArticleSQL Server – Calculating elapsed time from DATETIME
Elapsed time can be calculated from DATETIME field by extracting number of hours/minutes and seconds. You can use below query to calculate elapsed time between two dates: -- Vishal -...
View Article