Posts

Showing posts from July, 2014

Show animated wait window ,while processing request

Its a major problem faced while processing DB request else functions etc . The problem is when we perform command on database it takes time of few seconds, at that time my applications main window becomes halted. when i performs command on database execution returns on main application when whole command is executed on database. Just Like "NonQuery()" Lets assume we are working on asp.net 4.0 and sending request to view.  i am showing a form before it and closing that form after the command, but problem is i am putting a GIF image on the form, because exection is halted on main application, the gif don't shows animation until the command is executed. so that i putted it on a BackGroundWorker, but main thread is halted so its child tread also become halt. we can not put database transaction in background worker, becuase sometime working is depended on result retrieved from database, and we want to halt application untill data is not fetched, but in this case

Dynamic query in SQL

Dynamic query which nothing but conditional query which help to optimize query and improve performance of query. Currently using   [AdventureWorksLT2008R2] datbase as following : Try first EXEC ('SELECT * FROM SalesLT.Product') You can try following just for idea DECLARE @SQL NVARCHAR(max), @ParmDefinition NVARCHAR(1024) DECLARE @ListPrice money = 2000.0, @LastProduct varchar(64) SET @SQL =       N'SELECT @pLastProduct = max(Name)                    FROM SalesLT.Product                    WHERE ListPrice >= @param1' SET @ParmDefinition = N'@param1 money,                         @pLastProduct varchar(64) OUTPUT' EXECUTE sp_executeSQL      -- Dynamic T-SQL             @SQL,             @ParmDefinition,             @param1 = @ListPrice,             @pLastProduct=@LastProduct OUTPUT              SELECT [ListPrice >=]=@ListPrice, LastProduct=@LastProduct Tips : If you tried it, then also tried for Temp Ta

Paging in SQL Server

Image
Paging is one the functionality which we can achieved in many ways. So many plugins,technologies used for development. My sir already used in 2008, I think over to tried it in by different way. It found that Microsoft provides pagination feature with SQL Server 2012. We can acheived it by row_number() and minimum ids etc But from SQL Server 2012 we can do pagination by using FETCH and OFFSET. From above records, I need to split next 6 records after 32 Address ID. So doing pagination is a two-step process: - First mark the start of the row by using “OFFSET” command. Second specify how many rows you want to fetch by using “FETCH” command. Query :  1. Fetching records from 0 to above SELECT * FROM [Address]  order by AddressID offset 0 rows – start from zero Fetch Next 6 Rows only 2. Fetching records from 32 to next 6 records paging. SELECT * FROM [Address]  order by AddressID offset 6 rows  Fetch Next 6 Rows only [Still reading regar

NIHAR'S BLOG: Sequence : Auto Generated ID's in SQL Server 2012

NIHAR'S BLOG: Sequence : Auto Generated ID's in SQL Server 2012 : Hi friends , after long time come back with new excellent features of SQL Server 2012. Don't worry , I am not posting all features bec...

Reading text file in SQL Server

There are many option to read text file data and store it into database. We may have following options available for reading/storing/updating data into database 1.  Import and Export wizard of SQL Serve 2. SQL Server Integration Services 3. Using C# with SQL CLR will insert data into tables But , using few lines code of query need to execute in SSMS. SQL Server provides  " BULK INSERT "  Operation to read data from local system and store it into database tables. Steps : 1. First create text file with some name "Abc.txt" and enter values as nihar, Vishal, Vivek, Save and Copy path of file. 2. Open SSMS and create temp table for data insertion Create table temp_Data ( name nvarchar(20) ) 3.  Use following query to view operation BULK INSERT  Temp_data FROM   'D:\Abc.txt' WITH ( FIELDTERMINATOR  = ',' ,     -- Here you can use any delimiter for seperation ROWTERMINATOR  = '\n'   ); SELECT * FROM Temp_data o/P :  3 Rows Affect