sql-server-2008

Why calling a function takes much more time than direct execution of function code

假装没事ソ 提交于 2021-01-28 23:00:34
问题 In my SQL Server 2008 R2 database, I have a query which calls a function. Lately this query has started to execute very slowly. I found that the user-defined function is hampering all the query. I tried to execute this function alone and it took 40 seconds to finish, while previously it executed in 3-4 seconds. So I tried to execute code that is inside of function and executed in this 3-4 seconds. I cannot understand why executing code of function takes far fewer time than calling function

how to call web service from t-sql

僤鯓⒐⒋嵵緔 提交于 2021-01-28 18:17:50
问题 I'm using below code to call a web service, but its returning empty value. Please help me on this: Declare @Object as Int; Declare @ResponseText as Varchar(8000); Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT; Exec sp_OAMethod @Object, 'open', NULL, 'get', 'http://usadc-vsbbmd02:8085/rest/api/latest/plan/EP-AR','false' Exec sp_OAMethod @Object, 'send' Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT Select @ResponseText Exec sp_OADestroy @Object 回答1: You should use SQLCLR or an

Establishing the connection from Script Task(VB) to OLEDB Connection Manager of SSIS Package

一曲冷凌霜 提交于 2021-01-28 14:18:47
问题 How to use the existing OLEDB connection Manager from scripttask Task(VB). i need to execute a SQL statement from "Script Task" Task. Edit Attempted the following code but couldn't get the connection with my OLEDB Connectionmanager Dim MyCM As ConnectionManager = Dts.Connections("MyConnection1") Dim CS As String = Dts.Connections(MyCM).ConnectionString sqlConn = New SqlConnection(CS) 回答1: I would refer you to this most excellent blog post by Todd McDermid, Using Connections Properly in an

SQL Server(SQLEXPRESS) Service

北慕城南 提交于 2021-01-28 12:12:05
问题 I am trying to start SQL Server(SQLEXPRESS) service from Sql Server Configuration Manager. I got following error: The request failed or the service did not respond in a timely fashion. Consult the event log or other application error logs for details. I checked out error logs. Here is the error: initerrlog: Could not open error log file 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Log\ERRORLOG'. Operating system error = 3 How can I achieve this? 回答1: You need to make sure

SSRS Report - Dataset Filters

谁说我不能喝 提交于 2021-01-28 12:10:06
问题 I've written a report for SSRS and Im using dataset filters with expressions to filter the report info. I seem to either have this expression wrong or the filter is not working correctly: =IIf(Parameters!DoctorID.Value = "All" Or Parameters!DoctorID.Value = "", "*", Parameters!DoctorID.Value) What I want to accomplish with the above code is if DoctorID = ALL or "" (blank) then I want to omit it from the filters so I return information for all doctors. However, whenever the value of DoctorID =

Partial sum between different records using SQL 2008

早过忘川 提交于 2021-01-28 11:15:36
问题 I'm trying to solve this issue in SQL 2008. I've a table like this: DECLARE @table TABLE ( TimeStamp DATETIME, val INT, typerow VARCHAR(3) ); INSERT INTO @table(TimeStamp, val, typerow) VALUES ('2018-06-03 13:30:00.000', 6, 'out'), ('2018-06-03 14:10:00.000', 8, 'out'), ('2018-06-03 14:30:00.000', 3, 'in'), ('2018-06-03 15:00:00.000', 9, 'out'), ('2018-06-03 15:30:00.000', 4, 'out'), ('2018-06-03 16:00:00.000', 2, 'out'), ('2018-06-03 17:05:00.000', 8, 'in'), ('2018-06-03 17:30:00.000', 0,

Finding next row in SQL query and deleting it only if previous row matches

♀尐吖头ヾ 提交于 2021-01-28 08:07:46
问题 I have a table like this. |-DT--------- |-ID------| |5/30 12:00pm |10 | |5/30 01:00pm |30 | |5/30 02:30pm |30 | |5/30 03:00pm |50 | |5/30 04:30pm |10 | |5/30 05:00pm |10 | |5/30 06:30pm |10 | |5/30 07:30pm |10 | |5/30 08:00pm |50 | |5/30 09:30pm |10 | I want to remove any duplicate rows only if the previous row has the same ID as the following row. I want to keep the duplicate row with the datetime furthest in the future. For example the above table would look like this. |-DT--------- |-ID---

SQL Select MAX and 2nd MAX

我的未来我决定 提交于 2021-01-28 07:01:34
问题 I am running a query against MS SQL Server 2008 and am selecting an accountnumber and the max of the column mydate grouped by accountnumber: select AccountNumber, max(mydate), from #SampleData group by AccountNumber I want to add a column to the result that contains the second highest mydate that is associated with the AccountNumber group. I know it would have to be something like: select max(mydate) from #SampleData where mydate < (select max(mydate) from #SampleData) But how do I get both

SQL pivot data with dynamic list of columns

流过昼夜 提交于 2021-01-28 05:53:42
问题 Im stuck on a particular problem im hoping someone can help me out with. I have four tables Product, ProductType, Orders. I want to view Data from the Orders table but want to view it in a way where on each day the data is grouped by the sum of product quantity sold for each day under each ProductType. Please view the table structure, I have tried to get the Product groups as an array list and am able to sum the product quantity up for each product type group but cant figure out how to view

SQL Server 2008 stored procedure result as column default value

早过忘川 提交于 2021-01-28 04:38:03
问题 First of all, thank you guys. You always know how to direct me when I can't even find the words to explain what the heck I'm trying to do. The default values of the columns on a couple of my tables need to be equal the result of some complicated calculations on other columns in other tables. My first thought is to simply have the column default value equal the result of a stored procedure. I would also have one or more of the parameters pulled from the columns in the calling table. I don't