|
|
Browse by Tags
All Tags » T-SQL ( RSS)
-
|
My co-worker had a task of finding minimum alternate week day as of today for a given date and day Consider these data Date : 2009-12-22 day : 5 (it denotes Thursday) It means the event was scheduled on 2009-12-22 which should run on every alternate Thursday...
|
-
|
One of the questions asked in a forum was about replacing data of one table by the data of another table The solution that the questioner used was having cursor by looping through the source table and replace particular words by other words from another...
|
-
|
In the Query Analyser, set the Result mode to Text (Press CTRL+T) and run the following code set nocount on select space ( 17 - len ( replicate ( char ( 94 ), no )))+ replicate ( char ( 94 ), no * 2 - 1 ) from ( select top 10 row_number () over ( order...
|
-
|
Sometimes, you may need to find a value in the characters columns (char, varchar, etc) in all the tables This is one of the methods to do it declare @sql varchar ( max ), @search varchar ( 100 ) set @sql = '' set @search = 'your search string'...
|
-
|
In my previous post about Removing unwanted characters , I posted a method that used a function Here is another method that uses Dynamic SQL declare @data table ( data varchar ( 100 )) -- table that has source data insert @data select 'tes^@&t...
|
-
|
Now-a-days lot of questions are aked in the forum about extracting particular text from a string Here I give some examples on how to do it --Example 1 (Extracting tags and other informations) declare @s varchar ( 100 ) declare @temp table ( id int identity...
|
-
|
As you know, semicolon is used as a statement terminator in almost all RDBMSs. However the usage of semicolon is optional in SQL Server except a few cases. Here are atleast the three cases where usage of semicolon is a must 1 At the start of the Common...
|
-
|
One of the new features available in SQL Server 2008 is compressed backup which takes backup of a database with mimimum possible size. The syntax is backup database db_name to disk = 'backup_path' with init , compression But this works only in...
|
-
|
In this post script-out-procedures-and-functions-part-2 , I showed how to script out the procedures in a single file Here is another way to do the same but different file for each procedure declare @sps table ( proc_name varchar ( 100 ), texts varchar...
|
-
|
Suppose you want to import data from a text file to a table, one of the options is to use Bulk Insert command It allows to import data to the table, though one/more columns don't have enough size to get the maximum length of data from text file.It...
|
-
|
In http://ask.sqlteam.com , a question was asked about removing the comments from the HTML template The comments have the following pattern {/*}comment{*/} The comments can be nested too The task is to remove all the comments Here is my solution declare...
|
-
|
How do I find out the maximum length of each column in a table? Here is the answer declare @sql varchar ( 8000 ), @table sysname select @table = 'your_table' , @sql = '' select @sql = @sql + 'select ''' + @table + '''...
|
-
|
In SQL Forum one of the posters asked a question about dropping all the temporary tables There are many ways to do this One of the ways to to run the following code declare @sql varchar ( 8000 ) set @sql = '' select @sql = @sql + ' drop table...
|
-
|
Here are the queries that findout the cursors based on their statuses 1 Find out the cursors that are allocated but not opened or closed --Method 1 select name from sys.dm_exec_cursors ( 0 ) where is_open = 0 --Method 2 select cur . cursor_name from sys...
|
-
|
Generating the Fibonnaci series generally involves in writing the code which has while loop or a recursive function Peso posted here the code using the Common table expression Here are my methods that involves no loop or no recursion 1 Use Quirky update...
|
More Posts Next page »
|
|