Looping through database in a Linked server
If I wanted to run a standard query against every database on a server I could gather a list of the databases and loop through them or use the MSForEachDB method to do that. But what if I only have...
View ArticleUDFs vs Performance
My question concerns UDFs versus performance. I'm specifically referring to in-line use of UDFs. As far as I know, I have read that UDFs should be avoided where possible due to performance issues. My...
View ArticlePermit variables to be used as object names?
Does the SQL Server team have any plans to permit variables to be used as object references in T-SQL statements? As explained in http://support.microsoft.com/kb/65466, and as every db developer knows,...
View ArticleSQL syntax best practice
If I can find the Most recent address using:SELECT DISTINCT A.ClientKey, A.AdmissionKey, A.Address, A.CITY, A.State, A.ZIP, A.PhoneH, A.PhoneW, A.PhoneC FROM (SELECT ClientKey,...
View Articlesql performance issue
Our clients are experiencing the application slowness issues,from our end sql numbers are below 30% and still the appliation is slow,where should i go and test?Regardsk
View ArticleTransaction (Process ID 60) was deadlocked on lock resources with another...
Hi,I have the query like SELECT mp.* FROM dbo.PropertDetail mp LEFT JOIN dbo.PeropertyKey mk ON mp.KeyID = mk.KeyID WHERE mk.PropertyTime >= (SELECT DATEADD(HH, -2, MAX(PropertyTime)) FROM...
View ArticlePermission for Query on Linked Server tables
Hi,I have 2 servers - Server A and Server B. I have a view that queries tables in Server A. Results are fine.I create a synonym for tables in Server B. I then use this synonym in my views on Server A....
View ArticleRecords go missing with Nolock hint - results in deadlock if nolock hint...
I m currently doing my reads using the nolock hint, and updates using the rowlock hint. Here is the experiment setup:Thread 1: while (1 = 1) begin -- Perform a read operation on row 101. Read query...
View Articledelete millions of rows
hii need to move data to another table and then remove from old one ,which i needs to delete 30 millions of rows,i know its taking time but any idea i can do it faster like in a batch
View ArticleExtending Decimal Range Throws 8k Limit Error
Hi,I need to extend my decimal field range from decimal(8,4) to decimal(19,4), however, while doing so, it throws the following errorCommandalter table dbo.temp alter column field_1 decimal(19,4)...
View Articleinsert rows in million in batch
hii want do something liek thisdeclare @max intselect @max = count(*) from table1 a join table2 b on a.id = b.id and a.date>getdate()while(@max)insert into table ccolumn1,column2select * from...
View ArticleCheck For Null in Where Clause When Column is Numeric
I think my question is general enough to not require posting the DDL. I am and will be writing queries for menus that have two comboboxes. I currently have a menu where the user can make a selection...
View ArticleProblem with Restore Database
HiI have a problem for restore a database in a SQL Server 2008 Standard R2. The Database size is 20GB. When the progress is 50%, the system show the next error: ===================================...
View ArticleCheck if record exists in table for tables
Need to check if record exists or not. Target: Once table is for people which is at the master level.I have second table which records the phone numbers for people. Primary key from master table is...
View ArticleGroup Consecutive Club Membership Dates by Member and Membership Type
I have a database table that currently holds membership joining information (extract below) with one line for each year/period that a member have paid for membership; It is possible for a member to...
View ArticleJoining two tables on date fields summed.
Hi,I have a project I'm working on that has two SQL tables. I need to create a query that joins the two tables by org level and by date.Table 1 has the date columns like this :January February March -...
View Articleindexing silly noob question
I am a little confused on indexing.I have 10 million rows. each row has the name of a unique individual and their associated city (there are 1500 cities total):personName, cityNameMany times a day I...
View ArticleSingle Table Access
How to provide access to a single user/group to one table hiding the rest of the views and tables in a schema?
View ArticleQuery performance
Hello all,I create a big query which includes mutiple ctes and joins. and it is taking lot of cpu overhead and time. By running this i got to know that.exec sp_who2 'activeNow My teammate gave me...
View ArticleCASE Statements Causing Wrong Calculations
HI All,I am trying to add some conditional calculated fields within client and account data.This code returns exactly the right number of rows and the numbers in the 'closing balance' column are right....
View Article