My RDMS is the above. I have a stored procedure that takes 13 parameters. I have a table that holds those input values. I am pasting what I have done. Please help because its not executing. I am getting the following error: Incorrect syntax near '.'.
Please look at the attachment to see the location of the table I am trying to use.enter image description here
use ssisconfiguration.dbo.BalladHealthDayOneStats;
exec Clarity.ssis.sp_BalladDayOneMaster
[StatisticStartDate],[StatisticEndDate],[CostCenterList],[ProcedureCodeList],[Statistic],[StatisticDescription],[PatientTypeIndicator],
--[RVThreshold],[FiscalYear],
1,2017,
[PatientServiceList],[PatientClassList],[PatientStatusList]
The purpose of USE is to select the database.
i would suggest modify to
use ssisconfiguration
exec Clarity.ssis.sp_BalladDayOneMaster
([StatisticStartDate],[StatisticEndDate],[CostCenterList],[ProcedureCodeList],[Statistic],[StatisticDescription],[PatientTypeIndicator],
--[RVThreshold],[FiscalYear],
1,2017,
[PatientServiceList],[PatientClassList],[PatientStatusList])
replace the column name with values in the []
Related
SQL Server has Deferred Name Resolution feature, read here for details:
https://msdn.microsoft.com/en-us/library/ms190686(v=sql.105).aspx
In that page, all it's talking is stored procedure so it seems Deferred Name Resolution only works for stored procedures and not for functions and I did some testing.
create or alter function f2(#i int)
returns table
as
return (select fff from xxx)
go
Note the table xxx does not exist. When I execute the above CREATE statement, I got the following message:
Msg 208, Level 16, State 1, Procedure f2, Line 4 [Batch Start Line 22]
Invalid object name 'xxx'.
It seems that SQL Server instantly found the non-existent table xxx and it proved Deferred Name Resolution doesn't work for functions. However when I slightly change it as follows:
create or alter function f1(#i int)
returns int
as
begin
declare #x int;
select #x = fff from xxx;
return #x
end
go
I can successfully execute it:
Commands completed successfully.
When executing the following statement:
select dbo.f1(3)
I got this error:
Msg 208, Level 16, State 1, Line 34
Invalid object name 'xxx'.
So here it seems the resolution of the table xxx was deferred. The most important differences between these two cases is the return type. However I can't explain when Deferred Name Resolution will work for functions and when not. Can anyone help me to understand this? Thanks in advance.
It feels like you were looking for understanding of why your particular example didn't work. Quassnoi's answer was correct but didn't offer a reason so I went searching and found this MSDN Social answer by Erland Sommarskog. The interesting part:
However, it does not extend to views and inline-table functions. For
stored procedures and scalar functions, all SQL Server stores in the
database is the text of the module. But for views and inline-table
functions (which are parameterised view by another name) SQL Server
stores metadata about the columns etc. And that is not possible if the
table is missing.
Hope that helps with understanding why :-)
EDIT:
I did take some time to confirm Quassnoi's comment that sys.columns as well as several other tables did contain some metadata about the inline function so I am unsure if there is other metadata not written. However I thought I would add a few other notes I was able to find that may help explain in conjunction.
First a quote from Wayne Sheffield's blog:
In the MTVF, you see only an operation called “Table Valued Function”. Everything that it is doing is essentially a black box – something is happening, and data gets returned. For MTVFs, SQL can’t “see” what it is that the MTVF is doing since it is being run in a separate context. What this means is that SQL has to run the MTVF as it is written, without being able to make any optimizations in the query plan to optimize it.
Then from the SQL Server 2016 Exam 70-761 by Itzik Ben-Gan (Skill 3.1):
The reason that it's called an inline function is because SQL Server inlines, or expands, the inner query definition, and constructs an internal query directly against the underlying tables.
So it seems the inline function essentially returns a query and is able to optimize it with the outer query, not allowing the black-box approach and thus not allowing deferred name resolution.
What you have in your first example is an inline function (it does not have BEGIN/END).
Inline functions can only be table-valued.
If you used a multi-statement table-valued function for you first example, like this:
CREATE OR ALTER FUNCTION
fn_test(#a INT)
RETURNS #ret TABLE
(
a INT
)
AS
BEGIN
INSERT
INTO #ret
SELECT a
FROM xxx
RETURN
END
, it would compile alright and fail at runtime (if xxx would not exist), same as a stored procedure or a scalar UDF would.
So yes, DNR does work for all multi-statement functions (those with BEGIN/END), regardless of their return type.
I want to restore database in SQL Server 2008 R2 using a bak file and stored procedure of Lite speed. Below is my Code:
USE Master
Go
exec master.dbo.XP_RESTORE_DATABASE
#database="abc"
,#filename='M:\BACKUPS\xyz.bak'
,#WITH= 'REPLACE'
,#WITH= 'MOVE' "abc_DATA" TO "H:\SQLDATA\ABC.mdf"'
,#WITH= 'MOVE' "abc_LOG" TO "H:\SQLDATA\ABC.ldf"'
GO
After executing the above query I got below error:
Incorrect Syntax near 'abc_DATA'.
I don't know why I am getting this error as I always used this query to restore database.
This should work:
RESTORE DATABASE [abc]
FROM DISK = [DiskLocation]
WITH MOVE 'abc_data' TO ' H:\SQLDATA\ABC.mdf'
,MOVE 'abc_log' TO 'H:\SQLDATA\ABC.ldf'
XP_RESTORE_DATABASE isn't a SQL Server procedure. It's part of Quest's LiteSpeed product . The docs for xp_restore_database are here
Second, the message explains what's wrong. The call isn't correct. The string value passed to the #WITH parameter is terminated right after MOVE and followed by an object identifier "abc_DATA".
The call should be :
exec master.dbo.XP_RESTORE_DATABASE #database="abc", #filename='M:\BACKUPS\xyz.bak'
,#WITH= 'REPLACE'
,#WITH= 'MOVE "abc_DATA" TO "H:\SQLDATA\ABC.mdf"'
,#WITH= 'MOVE "abc_LOG" TO "H:\SQLDATA\ABC.ldf"'
You'll notice that syntax coloring paints the entire string red now.
Through SAS/ACCESS, I can successfully run data steps querying external DBMS tables. E.g.,
Data OutTable;
Set ExternalDBMS.Table1;
Where Var1 ='abc';
Run;
However, when column name has space, it caused a problem even I used ''n.
One example as shown below:
Data OutTable;
Set ExternalDBMS.Table1;
Where 'Var 2'n ='abc';
Run;
ERROR: CLI open cursor error: [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Incorrect syntax near the keyword 'Function'.
Further try with SAS Option validvarname=v7 to standardize the var names with spaces still caused same error.
After using SAS Option sastrace=',,,d' I found that SAS/ACCESS submitted statement to SQL server like this:
SELECT Var 1, .....
FROM schema1.Table1
WHERE (Var 1 ='abc' );
Apparently the code above would cause error in SQL server side because the Var 1 was neither quoted nor bracketed.
One way to fix it is using explicit pass-through query. I'm just wondering if there's any other ways to solve this problem too.
Thanks in advance!
when using an explicit pass-through query, put a set of square brackets around the variable name. This would be similar to how you'd write your code in SSMS.
SELECT [Var 1], ...
FROM schema1.Table1
WHERE ([Var 1] ='abc' );
I try to get pdf report by stimulsoft but get this error.
Incorrect syntax near '#StartDate'. Statement(s) could not be prepared
I test my stored procedure and table function in sqlserver and worked currently.but when I try to run VeiwData in dictionary window get me this error.
Query text in stimulsoft :
execute ProceGetCharterReportPdf (#StartDate,#endDate,#top,#AgencyName)
Type of #StartDate,#endDate,#AgencyName is nvarchar in report file and stored procedure and function .Type of #top is int.
It's going to sound daft, but try adding your schema name if you're calling a function;
execute dbo.ProceGetCharterReportPdf(#StartDate,#endDate,#top,#AgencyName)
You have to use the schema name when calling a function I believe, some further reading below;
Is it possible to call a user-defined function without the schema name?
Is there a way to use a function on a Microsoft SQL Server Query without using "dbo." before the function?
INSERT INTO [DEV_BI].dbo.[DimAktivitet]([Beskrivning],[företag],[Projektnummer],[Aktivitet],
loaddate)
SELECT NULL,
a.DATAAREAID,
a.PROJID,
a.MID_ACTIVITYNUMBER,
GETDATE()
FROM [?].dbo.[v_ProjCostTrans_ProjEmplTrans] a
LEFT OUTER JOIN [DEV_BI] .dbo.[DimAktivitet] b ON a.MID_ACTIVITYNUMBER = b.Aktivitet
AND a.DataAreaID = b.företag
AND a.ProjID = b.Projektnummer
WHERE b.Aktivitet_key IS NULL
I have this above sql code in execute sql task and in the parameter mapping i have mapped a variable named user::connectionstring with data type nvarchar , parameter name = 0. Im getting this following error.
[Execute SQL Task] Error: Executing the query "insert into [DEV_BI].dbo.[DimAktivitet]([Beskrivni..." failed with the following error: "Invalid object name '?.dbo.v_ProjCostTrans_ProjEmplTrans'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
please someone help me to solve this.
It appears you are trying to change the database based on a variable. The Execute SQL Task can only use parameters as filters in the WHERE clause. This behavior is described in this TechNet article. For instance, you could do this:
insert into [DEV_BI].dbo.[DimAktivitet]([Beskrivning],[företag],[Projektnummer],[Aktivitet],loaddate)
select null,a.DATAAREAID,a.PROJID,a.MID_ACTIVITYNUMBER,GETDATE() from
[DEV_BI].dbo.[v_ProjCostTrans_ProjEmplTrans] a
left outer join
[DEV_BI] .dbo.[DimAktivitet] b
on a.MID_ACTIVITYNUMBER = b.Aktivitet AND a.DataAreaID = b.företag AND a.ProjID = b.Projektnummer
where b.Aktivitet_key is null
AND b.SomeFilterCriteria = ?;
If you really want to vary the database based on a variable, then you have three options:
Vary the Connection Manager connection string to your database connection based on an expression as described in a blog post. This is the best solution if you are only changing the database and nothing else.
Generate the entire SQL code as a variable and execute a variable as the SQL command instead of passing variables to the Execute SQL Command. This is described in this blog post under the section "Passing in the SQL Statement from a Variable".
Create a stored procedure, pass the parameter to the stored procedure, and let it generate the SQL it needs on the fly.