I am debugging a stored procedure in Sql Server, I can see the local variables in "Locals", I can add other variables in "Watches" (I have embedded a picture here with Sql Server in debug mode and different debug windows).
My question is: where can I see the result of the select statements during debugging? It is really helpful to see them as they are executed, more so when they read from temporary tables sometimes, which are local to that procedure.
Later edit:
I have followed the advice given below and am having this problem with XML viewer (please see attachment): "The XML page cannot be displayed"
From View contents of table variables and temp tables in SSMS debugger:
This won't be in immediately, but we are considering a feature similar
to this for a future release.
And workaround (you need to add additional XML variable for each temp table):
Declare #TableVar_xml xml
Set #TableVar_xml = (Select * from #TableVar for XML Auto, Elements xsinil);
Then I can look at the table variable contents using the XML viewer.
Related
I have recently started using SQL Server 2016 and I'm using SESSION_CONTEXT values to pass some data around.
I'm trying to find out if there is any way to read all session context settings in one. To clarify this is for debugging purposes only - I can already access individual settings, (see code below). I would like to be able to read all such settings in one go if possible.
-- What I Have
EXEC sp_set_session_context 'SortOrder','Price ASC'
EXEC sp_set_session_context 'ItemsPerPage',20
SELECT SESSION_CONTEXT(N'SortOrder') [SortOrder]
SELECT SESSION_CONTEXT(N'ItemsPerPage') [ItemsPerPage]
SELECT SESSION_CONTEXT(N'NotSetYet') [NotSetYet]
-- What I'd like
SELECT * FROM SESSION_CONTEXT_TABLE
Any help gratefully received.
Many Thanks.
Session Context Stored in System pages so you can not retrieve the list of all context without having the key.
If you are looking for global parameters try to save as JSON, XML or CSV string and retrieve with the key.
I have a data flow working just fine, it is compound of a source that is evaluated by a lookup component and then it does an upsert, diagram is shown here:
Now, on BanqueCIBI (the ole db source), I have a SQL Command Text where I would like to receive a param from another component to use it as valueDate. This is the query right now:
SELECT [IdTransactionType]
,[IdBank]
,[IdBanqueDetailHistoryRef]
,[IdBanqueDetail]
,[IdBanqueHeader]
,[CCI]
,[ValueDate]
,[Text]
,[Reference]
,[Amount]
,[Sign]
,[IdCurrency]
,[OrigBranch]
,[dtCreatedOrModified]
,[oldText]
,[oldReference]
,[IdAccount]
,[IdSubAccount]
,[Date]
,[IdRD]
,[Flag]
,[History]
,[DtDate]
,[iTIB]
,[iSAP]
FROM [dbCibi3].[dbo].[BanqueDetailHistoryRef]
WHERE [ValueDate] = '2015-31-01'
So, the diagram would look something like this:
Right now, that new OLE DB Command looks like this:
And this is the usp_GetDateParamsSSIS invoked in the source above:
USE [dbMODIFE]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_GetDateParamSSIS]
#name VARCHAR(50) = NULL,
#value DATETIME OUTPUT
AS
BEGIN
SELECT TOP 1 #value =valueDate FROM helperPARAMS_SSIS WHERE name = #name;
END
So, how could I use that #value OUTPUT on the BanqueCIBI component? Thank you so much! (Please notice that BanqueCibi and the new component are querying different servers and a linked served is not an option because of company's policies).
Ok, since you are passing a hard-coded Name parameter to your stored procedure, I am assuming that this is a stored procedure you only need to call once for each execution of the package, and not something you're calling once for every row in your data source.
In that case, do NOT call the stored proc with an OLE DB Command in the data flow.
Instead, call it with an Execute SQL Task that you put BEFORE the DataFlow Task in the Command Flow. Direct the return value of the proc to a package-level variable.
Then in the Source of your dataflow (BanqueCIBI), map that variable to the first parameter of your SELECT query.
There are examples of all of these techniques easily available on the internet. But if you find one you are having trouble following, feel free to edit your question with the details, or create a new question if it is sufficiently different in scope from this one.
I have the following tasks in my SQL Server 2012 package:
Execute SQL Task to create a local temp table (I need to use local temp table as I will be firing off same concurrent packages)
Data Flow Task: To export from a SQL Server table into the local temp table created in step 1. I have the RatainSameConnection option = TRUE for data sources and DelayValidation for both tasks to true.
Once I run the package, I get this error:
The metadata could not be determined because statement
select * from #tmptable uses a temp table.
I researched this a lot but couldn't find a good solution. Any help and sample working SSIS package will be appreciated.
I just had this same issue and found the solution is to create a fake dataset in the query before you actual SELECT statement that SELECTs static data that is in the same format.
SET FMTONLY ON
select 0 as a, 1 as b, 'test' as C, GETDATE() as D
SET FMTONLY OFF
--now put the real query
select a, b, c, d from ##TempTable
See Kyle Hale's answer - SSIS Package not wanting to fetch metadata of temporary table
Go to properties and set ValidateExternalMetadata to False so it won't try to check the metadata.
If that doesn't solve the problem then,
Use global temporary table(##someTable) instead of local temp table(#someTable). so you can create that global temp table using SSMS and then when you use it in SSIS it won't complain about metadata.
Update:
If you want to use local temp table then do this after you've followed the above steps,
From SSIS menu in BIDS, select Work Offline mode and then change your Global temp table to Local temp Table. make sure do it from Property window or better use variable for holding sqlCommand text otherwise SSIS will complain about external metadata again.
Generally I replace the temp table with a CTE or table variable.
So I have a stored procedure in SQL Server. I've simplified its code (for this question) to just this:
CREATE PROCEDURE dbo.DimensionLookup as
BEGIN
select DimensionID, DimensionField from DimensionTable
inner join Reference on Reference.ID = DimensionTable.ReferenceID
END
In SSIS on SQL Server 2012, I have a Lookup component with the following source command:
EXECUTE dbo.DimensionLookup WITH RESULT SETS (
(DimensionID int, DimensionField nvarchar(700) )
)
When I run this procedure in Preview mode in BIDS, it returns the two columns correctly. When I run the package in BIDS, it runs correctly.
But when I deploy it out to the SSIS catalog (the same server the database is on), point it to the same data sources, etc. - it fails with the message:
EXECUTE statement failed because its WITH RESULT SETS clause specified 2 column(s) for result set number 1, but the statement sent
3 column(s) at run time.
Steps Tried So Far:
Adding a third column to the result set - I get a different error, VS_NEEDSNEWMETADATA - which makes sense, kind of proof there's no third column.
SQL Profiler - I see this:
exec sp_prepare #p1 output,NULL,N'EXECUTE dbo.DimensionLookup WITH RESULT SETS ((
DimensionID int, DimensionField nvarchar(700)))',1
SET FMTONLY ON exec sp_execute 1 SET FMTONLY OFF
So it's trying to use FMTONLY to get the result set data ... needless to say, running SET FMTONLY ON and then running the command in SSMS myself yields .. just the two columns.
SET NOTCOUNT ON - Nothing changed.
So, two other interesting things:
I deployed it out to my local SQL 2012 install and it worked fine, same connections, etc. So it may be a server / database configuration. Not sure what if anything it is, I didn't install the dev server and my own install was pretty much click through vanilla.
Perhaps the most interesting thing. If I remove the join from the procedure's statement so it just becomes
select DimensionID, DimensionField from DimensionTable
It goes back to just sending 2 columns in the result set! So adding a join, without adding any additional output columns, ups the result set to 3 columns. Even if I add 6 more joins, just 3 columns. So one guess is its some sort of metadata column that only gets activated when there's a join.
Anyway, as you can imagine, it's driving me kind of mad. I have a workaround to load the data into a temp table and just return that, but why won't this work? What extra column is being sent back? Why only when I add a join?
Gah!
So all credit to billinkc: The reason is because of a patch.
In Version 11.0.2100.60, SSIS Lookup SQL command metadata is gathered using the old SET FMTONLY method. Unfortunately, this doesn't work in 2012, as the Books Online entry on SET FMTONLY helpfully notes:
Do not use this feature. This feature has been replaced by sp_describe_first_result_set.
Too bad they didn't follow their own advice!
This has been patched as of version 11.0.2218.0. Metadata is correctly gathered using the sp_describe_first_result_set system stored procedure.
This can happen if the specified WITH results set in SSIS identifies that there are more columns than being returned by the stored proc being called. Check your stored proc and ensure that you have the correct number of output columns as the WITH results set.
In my organization, the standard is to comment all stored procedures with a comment block that looks like this:
/*-- =============================================
-- Created by: Chris McCall
-- Created date: 08.05.2009
-- Purpose: Inserts new setting value, code and description
-- Modifications:
-- <Date> <Programmer> <Change>
-- =============================================*/
I don't find this to be particularly useful, since the stored procedure is named usp_utl_CustomSettingsInsert anyway, and the comments are not guaranteed to be accurate. I usually ignore these blocks unless I have a problem and need to contact the original developer (who has long since departed, cackling maniacally, in a helicopter).
However, it's not up to me, so I have to do this. Is there any way, with a trigger or some other SQL Server magic, to create these comment blocks with nothing more than the power of my mind?
create a template in your editor
EDIT
If you want to alter the text of a procedure you can look at syscomments:
select text from syscomments where id=object_id('YourProcedureName') order by colid
If you put in long dummy tags like "<<:REPLACE XYZ:>>" in the source of the procedure, you could use: (I WOULD NEVER DO THIS AND DO NOT RECOMMEND THAT ANYONE ACTUALLY TRY THIS!!!)
UPDATE syscomments
set text=REPLACE(
REPLACE(text,'"<<:REPLACE NAME:>>','new name')
,'"<<:REPLACE DATE:>>',GETDATE()
)
where id=object_id('YourProcedureName')
If you're using SQL Server 2005...
Check out Template Explorer....you can find it in SQL Server Management Studio under View...then Template Explorer
Once in Template Explorer...go to the Stored Procedure section and take a look at the templates there.