This question already has answers here:
How to see query history in SQL Server Management Studio
(14 answers)
Closed 3 years ago.
I have a need to pull all the recently executed SQL statements from SQL Server. What is the log file and location that I need to look for.
Try This
SELECT B.TEXT AS [Query], A.execution_count [Count], A.last_execution_time AS [Time]
FROM sys.dm_exec_query_stats AS A
CROSS APPLY sys.dm_exec_sql_text(A.sql_handle) AS B
ORDER BY A.last_execution_time DESC
Related
This question already has answers here:
Query to Snowflake database isn't working because no active warehouse is selected
(2 answers)
No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command
(1 answer)
Closed 5 months ago.
i am just a beginner on snowflake.
I am using trial version.
I am trying run basic command of select * and Db i am taking is Snowflake sample data.
I am getting this error = 000606 (57P03): No active warehouse selected in the current session. Select an active warehouse with the 'use warehouse' command.
what am i missing?
We recently updated SQL Server from:
Microsoft SQL Server 2017 (RTM-CU9-GDR) (KB4293805) - 14.0.3035.2 (X64)
to:
Microsoft SQL Server 2017 (RTM-CU14-GDR) (KB4494352) - 14.0.3103.1 (X64)
In one of the extraction jobs we are using SQL like:
SELECT
XMLNode_Root.R.value('./#ID', 'INTEGER') AS [SellerID],
CAST(XMLNode_Root.R.value('../#ID', 'VARCHAR(25)') AS BIGINT) AS [ApplicationID]
FROM Stage.LoanAppl_XML AS AD
CROSS APPLY AD.ApplicationXMLPackage.nodes('//MessageResponse/body/Application/Seller') AS XMLNode_Root(R)
OPTION(USE HINT('ENABLE_PARALLEL_PLAN_PREFERENCE'));
Recently, on random occasions this select started to return NULL values for ApplicationID column even the ID is defined in the parent.
What is interesting:
1. If I do any change to SQL Select, like change case or add spaces it returns correct values.
2. Running dbcc freeproccache solves the problem for some time.
I have execution plan saved before and after clearing cache, but can't post it now.
I wonder if anybody had similar issue and was able to find a solution.
This question already has answers here:
How to run a SQL query on an Excel table?
(11 answers)
Closed 8 years ago.
I have one excel sheet(name as:-LTATestData.xls). It contain some column with corresponding some value. I want select sql query which read the column value from excel sheet and display the result.
I have tried to search in google, i get below query which may solve my purpose
SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 10.0;Database=C:\work\LTATestData.xls',
'SELECT * FROM [Sheet1$]')
But when I run this query I am getting below error message:- "OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode."
Please let me know how to do this. Thanks in advance.
The main cause for this might be because of a mismatch between a 64-bit SQL Server and a 32-bit Microsoft Office installation. Therefore rather upgrade to a 64-bit Microsoft Office than downgrade a sql server version.
Alternatively, here a couple of posts if your versions are all up to date (Please read the comments sections as well)
The following posts might be helpful solving the problem: HOW TO: FIX ERROR - "the 'microsoft.ace.oledb.12.0' provider is not registered on the local machine"
AND
SQL SERVER – Fix: Error: MS Jet OLEDB 4.0 cannot be used for distributed queries because the provider is used to run in apartment mode.
We have this recurring situation where several times a week our application stops responding. What I would like to do is be able to view the text of the query running on SQL Server.
I can use sp_who to see the open connections, but, it does not display the actual query text.
If I can see the query that is freezing my database I can have a starting point for optimization.
This happened a few minutes ago and our sys admin had to reboot the box. This rebooting is not sustainable.
What steps should I take?
I would like to see the actual text of the queries that are running on my server.
SQL Server 2000
use this while the block is happening:
SELECT
r.session_id AS spid
,r.cpu_time,r.reads,r.writes,r.logical_reads
,r.blocking_session_id AS BlockingSPID
,LEFT(OBJECT_NAME(st.objectid, st.dbid),50) AS ShortObjectName
,LEFT(DB_NAME(r.database_id),50) AS DatabaseName
,s.program_name
,s.login_name
,OBJECT_NAME(st.objectid, st.dbid) AS ObjectName
,SUBSTRING(st.text, (r.statement_start_offset/2)+1,( (CASE r.statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
ELSE r.statement_end_offset
END - r.statement_start_offset
)/2
) + 1
) AS SQLText
FROM sys.dm_exec_requests r
JOIN sys.dm_exec_sessions s ON r.session_id = s.session_id
CROSS APPLY sys.dm_exec_sql_text (sql_handle) st
WHERE r.session_id!=##SPID
this will list all active SPIDs, who is blocking them and the SQL of each SPID
EDIT
this query is for SQL Server 2005+, initial question did not state SQL Server 2000
See the article How to monitor blocking in SQL Server 2005 and in SQL Server 2000 for the definition of sp_blocker_pss08 (a SQL Server 2000 compatible script).
This question already has answers here:
Call stored procedure with table-valued parameter from java
(5 answers)
Closed 3 years ago.
How to pass Table-Valued Parameters (Array-like Parameter) to Stored Procedure in Microsoft SQL Server 2008 R2 using Microsoft SQL Server 2008 R2 JDBC Driver ?
Is it possible with jTDS?
The current (3.0) Microsoft driver doesn't support passing TVPs.
At one point, Microsoft was soliciting votes for TVP vs. Bulk Copy:
http://blogs.msdn.com/b/jdbcteam/archive/2011/09/22/tvp-or-bulk-copy.aspx
TVP got more votes, but it remains to be seen what actually got done. The most recent CTP for version 4.0 doesn't appear to have TVP support.
While this question was about SQL Server 2008, and while it really wasn't possible to pass table valued parameters at the time, it is now. This is documented here in the JDBC driver manual. For example, it could be done like this:
SQLServerDataTable table = new SQLServerDataTable();
table.addColumnMetadata("i" ,java.sql.Types.INTEGER);
table.addRow(1);
table.addRow(2);
table.addRow(3);
table.addRow(4);
try (SQLServerPreparedStatement stmt=
(SQLServerPreparedStatement) connection.prepareStatement(
"SELECT * FROM some_table_valued_function(?)")) {
// Magic here:
stmt.setStructured(1, "dbo.numbers", table);
try (ResultSet rs = stmt.executeQuery()) {
...
}
}
I've also recently blogged about this here.
I have solved this problem by myself. I have created CLR .Net Stored Proc with accepts a BLOB parameter. This BLOB is just a list of serialized INTs. It is possible to deserialize it using T-SQL or .Net CLR SP.
.Net CLR SP has better performance, which was really important for my project.