DECIMAL vs NUMERIC for ID values
We have ID columns with values with up to 10 digits. Those ID's are usually third (and last) segment in indices on various tables. Normally I define them as NUMERIC(10), but looking into other people's...
View ArticleInclude the first zero when converting time from datime into INT
I have [quote]declare @t datetime = '2016-11-02 07:22:26.320'SELECT LEFT(CAST(REPLACE(CONVERT(VARCHAR, @t, 108), ':', '') AS INT), 6)[/quote]which gives me INT value of 72226, and I want it to include...
View ArticleUsing Lag/Lead and OVER() to get growth pattern
Hi Guys,I've got a bit of a query problem that I am not quite getting where to start, to be honest. I think I know what bits I need to use just not sure how to bash all the parts together:I have a...
View ArticleWITH INDEX hint
I was recently trying to optimize a big SQL statement (a dozen of JOINs and APPLYs), commenting some joins and filters and looking at execution times and plans until I pinpointed the "culprit" JOIN...
View ArticleIs my use case a good fit for Unpivot and Pivot ?
I've been trying to use dynamic unpivot and pivot (thanks to some code examples from someone named "bluefoot" on stackoverflow that was posted in answer to a question three years ago) to solve the...
View ArticleDrill down values...
Hi,I've an orders table with customer and supplier (customer_id, supplier_id, order_id, order_date, ...)Is it possible to get the total orders from a customer and drill down to the supplier in the same...
View ArticleDynamic pivot and its effect on the plan cache
We have a heavily used GUI that displays specific business data in a pivot.A stored procedure is used to create the pivot, using dynamic SQL.The SP is using EXEC sp_executesql with parameters in the...
View Articlejoin two tables on Column where column has value specified more than once
I have two tables with below datatable 1Id name company1 aaa yyy1 aaa bbbtable 2Id designation1 manager1 managerWhen I join these on ID, I get 4 rows but instead I want to get two rows.target table:Id...
View ArticleSUM and Group using IN clause
Hi, I am looking for a way to create a query to SUM and Group BY by using IN clause similiar to below.Is this possible or is another method recommended?SELECT CID, SUM(Hours) WHERE CID IN mycodes,FROM...
View Articlehow to trace the effected table when a primary table is updated/inserted
Hi,When we update/insert any table how do we know which other tables are effected in sql server? If we are using SQL profiler how do we set it up?
View ArticleQuestions on filetables
Currently we have a process that dumps 20 million records into regular tables in database every 15 minutes. The data is transitory and we only need to keep it for 24 hours. Since the data is transitory...
View ArticleSplit Record by Field into Multiple Records
Hello all,I have a table that I need to split up the records into multiple records by and Integer field. Here is what the table is like and what it should look like. Thanks/*** This is the Original...
View ArticleSproc/view/function code parser
Hi - I'm looking for a code parser for SQL Server 2014 - ie something that I can point at a sproc or view or function and get feedback as regards code quality, readability bulletproofing...
View ArticleDetermine if a table column is used?
Does anyone know if there's any way you can determine if a column in a table is used or not?I have a table with 926 columns (I didn't build this), of which about 850+ of them appear to have NULL values...
View ArticleIndexes on Views - with UNION
Hi Team,Want to create a view using below query, and also want to apply indexes on that view.[quote]SELECT NT.ID, U.acc_name FROM dbo.NR_VT NT WITH (NOLOCK), dbo.ACCOUNTS U WITH (NOLOCK)WHERE NT.VT =...
View ArticleThe financial situations of the various top tier teams.
[url=https://gapp.usc.edu/sites/default/files/webform/HD-Vargas-vs-Pacquiao-Live-Stream-2016-PPV-Big-Fight-results-and-round-by-round-5-Nov-2016.pdf]Vargas vs Pacquiao Live Streaming[/url]
View Articlewhere condition on same column doesnt return data
i have a question, below query doesn't return any data. application is allowing filters on same column. Is there any other to make it work[code="plain"]/*-------------------------Drop temp...
View ArticleHow to use a CSV as parameter in a query
I always used a query with an(one) integer parameter, but now it has to change to more integers in the parameter. [u]Before:[/u]DECLARE @Param INT SET @Param = 1SELECT * FROM Trips WHERE TripID =...
View ArticleERROR INSERT with db link 4 partname to oracle
i have somthing strnage.when i run this command in mssql insert into [LinkedSRV]...[xfer_in_order] (seq_id, action_type, action_code)values(2001, 'PTL_TEST', 'M') i get error :OLE DB provider...
View ArticleInserting records failing everyday
We have one schedule job which dropping and inserting records into table on daily basis. But this job is failing due to "Could not allocate space for object 'dbo.SORT temporary run storage:...
View Article