what happens when a Stored procedure shared by two jobs and get called at...
Hi All, Not sure its the right way to do it , I wrote a MASTER SP which calls three different SP using variables passed to MASTER SP.MASTER SP calls the three SP using EXECUTE IMMEDIATE COMMAND, My...
View ArticleChallenging T-SQL Query
I am using SQL Server 2008My data looks like thisname id data ==== === ===== cxyz 2 coffee jojo 3 barley moto 4 jasmine samie 1 elda dunk 2 tarmal sihoo 3 newcome iblie 2 acost samou 17 ikea I want the...
View ArticlePIVOT versus UNION for de-flattening (normalizing?) some (but not other)...
We have a table with 500+ columns. The data is non-normalized, i.e. there are four groups of fields for for "people", followed by data that applies to all people in the row (a "household").For ad-hoc...
View ArticleHow to delete records by age and keep only the 2 most recent for a set of key...
I need to come up with a purge routine to keep only the two most recent records for each set of key fields. For instance in this table:CREATE TABLE [dbo].[Profile_Actuals]([EffectiveDate] [datetime]...
View ArticleCan someone help me diagnose a strange stored procedure performance issue...
I have a stored procedure (posted below) that returns message recommendations based upon the Yammer Networks you have selected. If I choose one network this query takes less than one second. If I...
View ArticleMerge multiple rows of same ID into Single row
Hi All,I need the requirements of merging multiple rows of same ID as single row.My Table Data:ID Language1 Language2 Language3 Language4 1001 NULL JAPANESE NULL NULL 1001 SPANISH...
View ArticleUsing Calculated Columns in Further Calculations
Hi,We have a situation where we need to calculate a value in a select statement and then use the result of that calculation in another calculation in the same statement - something along the lines...
View ArticleYielding the desired number of decimal places using the AVG function in t-sql
Hello again. Confused retired hobby coder having trouble setting up a scalar-valued function to return the desired number of decimal places from a AVG query.Whenever I run the following script I get...
View Articlestill no subroutines in t-sql?
Hi. We run 2012 std. I know all the arguments for and against but am wondering if t-sql has introduced the concept of a subroutine yet? This would be contained in the sproc but for readability...
View ArticleUsing Cast With Case
I want my answer to be in decimal format, showing 4 decimal places. I attempted this, and it shows me the error of Incorrect syntax near 'CAST', epected 'As'Select Round(Avg(Cast(case when isfarm =...
View ArticleUnion of multiple CTE'S
Hello,I have a piece of code which goes like this ---A]with cte1 AS (), cte2 as (),select a,b,c B]with cte3 AS (), cte4 as (),select x,y,z.I need a way to union these 2 result sets. I can't write all 4...
View ArticlePassing String Which Has Single Quote Row/Value to a Function Returns Double...
Hi, I'm getting weird thing in resultset. When I pass String which has single quote value in it to a split function , it returns rows with double quote. For example following string:'N gage, Wash 'n...
View ArticlePerformance - reading the query cost
Which of these three represent the most efficient query? I'm wondering if the smallest plan in bytes is the best plan. Also, are eager spools expensive or inexpensive, and is a smaller sub-tree cost...
View ArticleLeft/Right Outer Join
When we call the Left/Right Outer Join, what Left/Right means?From where left/right does it mean?For example,SELECT C.custid, C.companyname, O.orderidFROM Sales.Customers AS C LEFT OUTER JOIN...
View ArticleSQL Help on Query
HI All,I have a table with below data ID VoucherID ClientID Subdate AmtRed RedeemDate ServiceType1 ServiceType2 ServiceType3 1 123 ABC 2014-07-24 1000...
View ArticlePIVOT with multiple columns to add and multiple levels of grouping
Hi friends,I got a table with the columns in the form of:CRITERIA_A,CRITERIA_B,CRITERIA_C,AMOUNT_A,AMOUNT_B,AMOUNT_C,AMOUNT_DAny way to design a pivot to present the table reflecting:Sums of Amount_A,...
View ArticleHow can I convert SQL Server 2008 Timestamp to DB2/iSeries Timestamp?
In DB2/iSeries I have a column that accepts Timestamp value. When I try to insert a timestamp value from the SQL 2008 table and into DB2/iSeries table I recieve the following error message:OLE DB...
View Articlecalculated field with decimal place
Hello,if I create calculated field in a table using formula e.g., ColumnName/ 60, where format of ColumnName is INT (total ammount of minutes) in order to get hours, I get only integer part, not...
View ArticleSQL Server 2008 R2 SP2 buildnumber: 10.50.4000.0 or 10.52.4000.0 ?
We have some confusion about the SQL Server 2008 R2 SP2 buildnumber. Could anyone explain why we see both 10.50.4000.0 as 10.52.4000.0? Or is there an intentional difference between the SP2 patch...
View ArticleFinding minimum value in each row using dynamic query
need to find the minimum and maximum value from each row using dynamic query[from curr] will be given as inputTuky
View Article