TSQL Cast Vs Convert

SQL Server programmers can choose between two functions in SQL Server 7 and 2000 for converting expressions from one type to another. In many cases there will be a need within a stored procedure or other routine to convert data from, say, a datetime type to a varchar type; CONVERT and CAST are used for such things. Because SQL Server provides both functions, there may be some confusion about which is best to use and under what circumstances. CONVERT is specific to SQL Server, and allows for a greater breadth of flexibility when converting between date and time values, fractional numbers, and monetary...

Insert multiple records with single Insert statement in SQL

This is the traditional method for inserting multiple values in a table. USE YourDBName GO INSERT INTO MyTableName (FirstCol, SecondCol) VALUES (‘First’,1); INSERT INTO MyTableName (FirstCol, SecondCol) VALUES (‘Second’,2); INSERT INTO MyTableName (FirstCol, SecondCol) VALUES (‘Third’,3); INSERT INTO MyTableName (FirstCol, SecondCol) VALUES (‘Fourth’,4); INSERT INTO MyTableName (FirstCol, SecondCol) VALUES (‘Fifth’,5); GO However this cannot be used if you want to insert multiple values into the table via your code because in this case you’ll have to write the code...

Finding a column in database

Here is the query that will help you to find a particular column in the database. This query will return you the table name in which that column is found. select so.name, sc.name from syscolumns sc inner join sysobjects so on sc.id = so.id where sc.name = 'SystemColumn'

Data Scripter Add-in for SQL

Many a times you feel the need to script databases, tables, stored procedures etc. But you already have these utilities that help you to script these database objects. There is no script generator for the data present in the table. For e.g. you want to move data from one server to another, to accomplish this you have the script generator for table but not for data within it. There is an Add-on for the SQL Management studio that helps you to generate the Table data scripts. You can download the add-in from here. After installing, when you right-click on a table node in Management Studio, you...

Query to list all tables and columns in database

Here is the SQL query that will help you list all the tables and columns along with its data type and length in a particular database. This query fires query to the system table that stores all the information about the database. select table_name, column_name, data_type, character_maximum_length, is_nullable from information_schema.columns where table_name in (select name from sysobjects where xtype='U') order by table_name Hope this helps, enjoy
Page 1 of 41234