possible to lock a table until while loop is finished
I have a while loop that loops through temp table T and deletes data from table A using values from a temp table T. It seems like users can read from table A as the while loop is still executing -...
View ArticleSum In Sub Query
Hi,How to get sum of quantity from each table based on Recipe Id from Raw Material Preparation table.Ex: Raw material preparation table can have multiple records in Vacuum mixing table like wise Vacuum...
View ArticleSCD Type 2
Hi All,I have a typical requirement of implementing a Type 2 scd for following tableStaging Table MEMBER_ID,COV_MTH_ID,RELATION,MARITAL_STATUS 1001 201401 10 M 1001...
View ArticleQuery to split one row to multiple based on date range
Hi,I need to split single row into multple based on date range defined in a column, start_dt and end_dtI have a data ID From date End_dt measure1 2013-12-01...
View ArticleError converting data type nvarchar to datetime
[Using SQL Server 2008 R2 Enterprise x64 SP1]I am trying to use some form of GETDATE() to pass today's date to a stored procedure inside OPENQUERY(), but I keep getting the errorMsg 8114, Level 16,...
View ArticleGrouping all in one row
Hi guys, I got a black out. I got this situation:Create table Forum ( Icity varchar(50), IMonth int, Iyear int, ACons int, BCons int, CCons int) insert into forum values ('Buenos...
View Articlechanging datetime column to hourly time
Dear All,I have a script that generates a memory report every 5 minutes. One of the columns is DATETIME, which gives the date and time of the memory collected every 5 minutes. I am asked to provide an...
View ArticleUpdate temp table with alias
I have query like this:SELECT o1.q_sum, c.q_sum FROM CTE1 c INNER JOIN #order o1 ON o1.col1=c1.col1It works. I get c.q_sum different from null for every row, while o1.q_sum is null.But if I write like...
View ArticleSET IDENTITY_INSERT ON failed
We have a table with identity column, InsertID, which is decimal (18, 0) NOT NULL. I got an error "arithmetic overflow error converting varchar to data type numeric" with "SET IDENTITY_INSERT tablename...
View Articlenumber of open actvities each end of month - closing balance, running totals
Hello,I'm using sql 2008 R2 standard edition.I have a table containing activities with columns ActivityID, StartDate, EndDate. Few sample data:acvtivityID StartDate EndDate12345...
View ArticleClustered Index uses Binary Tree or Balanced tree
Hi All,In the below mentioned link -- it says clustered index uses Binary treehttp://www.codeproject.com/Articles/173275/Clustered-and-Non-Clustered-Index-in-SQLwhere as in the Querying SQL Server...
View ArticleConditionnal lag/lead?
Hi,is there a way to use the lag and lead function with conditional?I want to get the next sales date where the date is not the same as the current row date.When I have multiple sales the same day, the...
View Article"String or binary data would be truncated" and field specifications
Hi all, i have "String or binary data would be truncated" error when i try to execute an insert statment. can i find witch field is affected by this error? (for return it to the user) thank's all
View ArticleHow to use ISNULL with this select statement
Hello All!I have this SELECT statement.SELECT pref.value('(caseNo/text())[1]', 'varchar(20)') as CaseNumber, pref.value('(countyNo/text())[1]', 'int') as CountyNumber,...
View ArticleUpdate with dynamic top value in CTE
Hi,Scenario : I have 2 main tables. One is header level and another is detail level. Each header table records have multiple detail entries based on the header table Quantity. Eg: The header have...
View ArticleStored procedure returning multiple result sets
Hello, I have a stored procedure that I've been tasked to add functionality to. The stored procedure executes a select statement and returns one record, and I need to add failover to it. Let's say I...
View ArticleLogging Transact-SQL scripts
Is there anyway to log when Transact-SQL scripts are run, by who, and their content ? (not necessarily what changes were made)I'm working on a site still using SQL Server 2008, but the DBAs here are...
View Articlehelp with query - inner join and case
Hi this is the query I am having troble with, where is the correct place to add the case condition:SELECT * FROM END_USER_ORDERS EO INNER JOIN ORDER_PRODUCTS OP ON EO.EUO_ID = OP.EUO_ID INNER JOIN...
View ArticleDivide column X By Y when Y is Greater than Zero
How do I accomplish this task using T-Sql: If column A > 0,(B/A) *100 ?Basically, I am checking that column A is not equal to 0 before dividing column B by a so I do not get error. Thank youZionlite
View Articlemixed collation
I have different collation in my database then on the server. Every time when i define temp table inside query I also set its collation to database collation - to prevent collate conflicts.But what...
View Article