how to optimise update query
Hi, If following query, i tried to check the plan i noticed both where same pls suggest as thum of rule what should be followed. thought i will check plans in each cases. 1) update t1 set a, b, c, d...
View ArticleCASE is rounding up to full number
HiI have a problem with a case function that I hope someone can help me with.I have the following code:CASE WHEN S.SumOfSchedule_Qty > 0 THEN (S.SumOfSchedule_Qty - 1) / S.Pallet_Qty)ELSE 0 END AS...
View ArticleTop 10 sum & count
I have been working on this Select statement all day (blogs & testing) and I guess it's time to seek some help.This is for my golf league to determine who is in the lead and determine the points...
View ArticleMS SQL - Number of a specific value within a single row
Hi,I have a sql table like the above. I would like to calculate the number of Reds for each row and add it as another column.For example I would like to add another column called RAG Reds. For ID 1...
View ArticleQuerying XML Data from a table
Hi,I was wondering what the easiest way is to select/extract data from XML. Its rather confusing and I have been getting a bit confused with how to do this. I need to be able to select/extract the data...
View ArticleConverting rows to columns using t-sql
Hi All,I have a table with 3 columns, let say ID1 , ID2, FlagMy Source data looks like this..ID1 ID2 Flag 1 1 0 1 2 0 1 3 0 2 7...
View ArticleUsing PRINT function
Hello,The piece of code I am working on is expected to return the string below:This script is testing the use of N' and is working fineHere is the actual script: DECLARE@SQL VARCHAR(MAX) SET @SQL =...
View ArticleSplit the string at every 2nd colon using t-sql
Hi All,I have a table with one column lets say Notes of datatype varchar(max)NotesABC:123:XYZ 456789:CDEF:ADEF CBD:12/12/2000:ZXCVI want Output should look like below. It should split data at every 2nd...
View ArticleQuery for fulfilment orders
I have table with orders and table with stock. The oldest stock(stock_id) must fill up the oldest orders (order_id) for appropriate item.I have created some test data and the required result. The logic...
View ArticleHow to get accurate values for select statement using single column
Hi All,Below is my query which runs fineSelect Distinct Top 4 FiscalYearId, FiscalMonthOfYearId From ODS.Common.tODS_Date Inner Join UTL.Utility.tUTL_ProcessDate On tODS_Date.DateShort <...
View ArticleChange Value based on Dynamical Object
Goal: The goal is to make the variable with value '2014-06-14 09:00:00.000' Problem: The syntax code is created as a dynamical object how do you make it from '2014-06-14 16:20:10.000' into value...
View ArticleSearch for columnName and Split data based on that column name
Hi All,I have a table with one column, lets say Notes of datatype varchar(max).Source Date:NotesABC:123:XYZ Dept:IT NameID:1 Name:Tom Hummer Date:04/12/2004 456789:CDEF:ADEF CBD:12/12/2000:ZXCV Dept:HR...
View ArticleSplitting one column into different columns.
Hello Experts,How do i split datetime column into different columns while doing a Select statement.Ex:The column "REC_CRT_TS" has data like "2014-05-08 08:23:09.0000000".The datatype of this column is...
View Articlehow to add blank rows between groups of duplicate rows?
here is my setupcreate table #tmpA(rowID int identity(1,1), fName varchar(10), lName varchar(10))insert into #tmpA select 'a', 'b' union all select 'a', 'b' union all select 'c', 'd' union all select...
View ArticleGrouping a data small datetime
Hi guys, I got data that come from Oracle, finally I got a good structure , everything is good but this issue:203 2013-04-18 14:45:19.0000000 100203 2013-04-18 14:45:25.0000000 85just as sample, I...
View ArticleThorny issue
Ok bad joke really and not really an issue - although quite annoying.The guys on the SQL Server team are obviously very intelligent and very thorough, but you're taking things too far when the...
View ArticleMerge Query
I`m running a Merge query I want to know is there a way after I run this query I can get a resulset which gives methe columns where the values have been updated? and when not matched what rows got...
View Articlecount (case when) not working in sql
Hi All,I am trying to find the count of members for a perticular date range, it seems not working correclty.Could any one help me out.here is the query...I am getting same output for all the...
View ArticleRecursive Cte Help
Hi, I am trying to parse a string based on the ":" identifier . Basically from the single string I need to parse data appended as follows:While Executing I get the error :Msg 537, Level 16, State 3,...
View ArticleWhat is the best approach to track deleted records
Dear all,We have build a CMS platform which is based on SQL server 2012 tables structure hosted in Azure. We have build on top of this some REST API method in order to access data from any type of...
View Article