Showing posts with label parameter. Show all posts
Showing posts with label parameter. Show all posts

Wednesday, March 21, 2012

problem passing UDF scalar result to UDF table function

I'm having difficulties invoking a user defined table function,
when passing to it a parameter that is the result of another
user defined function.

My functions are defined like so:

drop function dbo.scalar_func
go
create function dbo.scalar_func()
returns int
begin
return 1
end
go

drop function dbo.table_func
go
create function dbo.table_func(@.p int)
returns table
return (select @.p as id )
go

Given the above, I can do the following:

Select from the scalar function works:
1> select dbo.scalar_func() as scalar_result
2> go
scalar_result
----
1

Selecting from the table function works, if i pass a
constant value (or a variable)

1> select id from dbo.table_func(1)
2> go
id
----
1

But, if I try to pass the table function the return value
of the scalar function in one call, it doesn't work,
producing the following error:

1> select id from dbo.table_func( dbo.scalar_func() )
2> go
Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '.'.

What am I missing here?

Thanks kindly"roger" <rogerr@.softix.com> wrote in message news:f6e08af1.0405012257.4c2472cf@.posting.google.c om...

<snip
> But, if I try to pass the table function the return value
> of the scalar function in one call, it doesn't work,
> producing the following error:
> 1> select id from dbo.table_func( dbo.scalar_func() )
> 2> go
> Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near '.'.
> What am I missing here?
> Thanks kindly

It's barking at the period in the nested call. Try running it without qualifying the function name:

1> select id from dbo.table_func( scalar_func() )

--
Paul Horan
VCI Springfield, MA|||roger (rogerr@.softix.com) writes:
> But, if I try to pass the table function the return value
> of the scalar function in one call, it doesn't work,
> producing the following error:
> 1> select id from dbo.table_func( dbo.scalar_func() )
> 2> go
> Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near '.'.
> What am I missing here?

I don't think you can pass expressions as parameters to table-valued
functions; you can only pass constants and variables.

However, I was looking around in Books Online, but I could not find
a passage which actually says so.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||"-P-" <ent_must_dieAThotmailDOTcom> wrote in message news:<UI2dnT_yvLdgPQndRVn-hQ@.adelphia.com>...
> "roger" <rogerr@.softix.com> wrote in message news:f6e08af1.0405012257.4c2472cf@.posting.google.c om...
> <snip>
> It's barking at the period in the nested call. Try running it without qualifying the function name:
> 1> select id from dbo.table_func( scalar_func() )

No, that isn't it.

You have to qualify a scalar function with the owner name.
Curiously, you don't have to qualify a table valued function
in this way.

So, this works
select * from table_function()
but this does not
select scalar_function() from table
requiring instead
select dbo.scalar_function() from table.

I can't see any particular rhyme or reason to this,
it's just the way it seems to be.|||roger (rogerr@.softix.com) writes:
> So, this works
> select * from table_function()
> but this does not
> select scalar_function() from table
> requiring instead
> select dbo.scalar_function() from table.
>
> I can't see any particular rhyme or reason to this,
> it's just the way it seems to be.

The reason is that with out the reqiurement of a two-part name there
would be no possibility to distinguish between scalar system functions
and scalar UDF. And if they look the same syntactically, they share the
same name space, which would mean that each time MS added a new system
function, they would risk to break existing code.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

problem passing UDF scalar result to UDF table function

I'm having difficulties invoking a user defined table function,
when passing to it a parameter that is the result of another
user defined function.

My functions are defined like so:

drop function dbo.scalar_func
go
create function dbo.scalar_func()
returns int
begin
return 1
end
go

drop function dbo.table_func
go
create function dbo.table_func(@.p int)
returns table
return (select @.p as id )
go

Given the above, I can do the following:

Select from the scalar function works:
1> select dbo.scalar_func() as scalar_result
2> go
scalar_result
----
1

Selecting from the table function works, if i pass a
constant value (or a variable)

1> select id from dbo.table_func(1)
2> go
id
----
1

But, if I try to pass the table function the return value
of the scalar function in one call, it doesn't work,
producing the following error:

1> select id from dbo.table_func( dbo.scalar_func() )
2> go
Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '.'.

What am I missing here?

Thanks kindly"roger" <rogerr@.softix.com> wrote in message news:f6e08af1.0405012257.4c2472cf@.posting.google.c om...

<snip
> But, if I try to pass the table function the return value
> of the scalar function in one call, it doesn't work,
> producing the following error:
> 1> select id from dbo.table_func( dbo.scalar_func() )
> 2> go
> Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near '.'.
> What am I missing here?
> Thanks kindly

It's barking at the period in the nested call. Try running it without qualifying the function name:

1> select id from dbo.table_func( scalar_func() )

--
Paul Horan
VCI Springfield, MA|||roger (rogerr@.softix.com) writes:
> But, if I try to pass the table function the return value
> of the scalar function in one call, it doesn't work,
> producing the following error:
> 1> select id from dbo.table_func( dbo.scalar_func() )
> 2> go
> Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near '.'.
> What am I missing here?

I don't think you can pass expressions as parameters to table-valued
functions; you can only pass constants and variables.

However, I was looking around in Books Online, but I could not find
a passage which actually says so.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||"-P-" <ent_must_dieAThotmailDOTcom> wrote in message news:<UI2dnT_yvLdgPQndRVn-hQ@.adelphia.com>...
> "roger" <rogerr@.softix.com> wrote in message news:f6e08af1.0405012257.4c2472cf@.posting.google.c om...
> <snip>
> It's barking at the period in the nested call. Try running it without qualifying the function name:
> 1> select id from dbo.table_func( scalar_func() )

No, that isn't it.

You have to qualify a scalar function with the owner name.
Curiously, you don't have to qualify a table valued function
in this way.

So, this works
select * from table_function()
but this does not
select scalar_function() from table
requiring instead
select dbo.scalar_function() from table.

I can't see any particular rhyme or reason to this,
it's just the way it seems to be.|||roger (rogerr@.softix.com) writes:
> So, this works
> select * from table_function()
> but this does not
> select scalar_function() from table
> requiring instead
> select dbo.scalar_function() from table.
>
> I can't see any particular rhyme or reason to this,
> it's just the way it seems to be.

The reason is that with out the reqiurement of a two-part name there
would be no possibility to distinguish between scalar system functions
and scalar UDF. And if they look the same syntactically, they share the
same name space, which would mean that each time MS added a new system
function, they would risk to break existing code.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Erland Sommarskog <sommar@.algonet.se> wrote in message news:<Xns94DEEA82AECD9Yazorman@.127.0.0.1>...
> roger (rogerr@.softix.com) writes:
> > So, this works
> > select * from table_function()
> > but this does not
> > select scalar_function() from table
> > requiring instead
> > select dbo.scalar_function() from table.
> > I can't see any particular rhyme or reason to this,
> > it's just the way it seems to be.
> The reason is that with out the reqiurement of a two-part name there
> would be no possibility to distinguish between scalar system functions
> and scalar UDF. And if they look the same syntactically, they share the
> same name space, which would mean that each time MS added a new system
> function, they would risk to break existing code.

Oracle PL/SQL uses the keyword TABLE to introduce a function
that returns a table. eg

select * from table(my_user_function(args))

I would have thought that the context in which the function
is being called would tell you whether a scalar or table result
is required, but maybe there are more scenarios than I can imagine
off hand.

Using the qualified name to distinguish the function return type,
if that is really what that is about, is truly horrid.

As is not being able to pass the result of another function as
an argument. Kind of smells like this stuff was added in a hurry.

Still, I'm thankful that it is there at all I guess.|||Erland Sommarskog <sommar@.algonet.se> wrote in message news:<Xns94DEEA82AECD9Yazorman@.127.0.0.1>...
> roger (rogerr@.softix.com) writes:
> > So, this works
> > select * from table_function()
> > but this does not
> > select scalar_function() from table
> > requiring instead
> > select dbo.scalar_function() from table.
> > I can't see any particular rhyme or reason to this,
> > it's just the way it seems to be.
> The reason is that with out the reqiurement of a two-part name there
> would be no possibility to distinguish between scalar system functions
> and scalar UDF. And if they look the same syntactically, they share the
> same name space, which would mean that each time MS added a new system
> function, they would risk to break existing code.

Oracle PL/SQL uses the keyword TABLE to introduce a function
that returns a table. eg

select * from table(my_user_function(args))

I would have thought that the context in which the function
is being called would tell you whether a scalar or table result
is required, but maybe there are more scenarios than I can imagine
off hand.

Using the qualified name to distinguish the function return type,
if that is really what that is about, is truly horrid.

As is not being able to pass the result of another function as
an argument. Kind of smells like this stuff was added in a hurry.

Still, I'm thankful that it is there at all I guess.|||roger (rogerr@.softix.com) writes:
> Oracle PL/SQL uses the keyword TABLE to introduce a function
> that returns a table. eg
> select * from table(my_user_function(args))
> I would have thought that the context in which the function
> is being called would tell you whether a scalar or table result
> is required, but maybe there are more scenarios than I can imagine
> off hand.

The issue is about distinguishing scalar functions from table functions.
The issue is about distinguishing different sorts of scalar functions,
system functions vs. user-defined ones. SQL Server have no problem
to tell whether you are using a table-valued or scalar function. Or
more correctly: there are no places in the grammar where you can use both.

The system functions had already invaded the flat name space for

SELECT fun(x)

Of course, there are a couple of more options MS could have chosen. For
instance decide that all future scalar system functions would have a
prefix.

This is actually what they have done for table-valued functions:

SELECT * FROM ::fn_helpcollations()

This was possible, since there was no table-valued system functions
prior to SQL2000.

> As is not being able to pass the result of another function as
> an argument. Kind of smells like this stuff was added in a hurry.

It is quite consistent with how you call stored procedures. You
cannot pass expressions in calls to stored procedures with the
EXEC statement. And in fact, you can invoke scalar functions with
the EXEC statement too.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.aspsql

Problem Passing Report Parameters in URL

I'm currently trying to create a report that will take one parameters in the URL to generate a detail report. when i pass parameter as

http://marshad/ReportServer?/UpdatedByClickTest/S&rs:Command=Render&P1=123

it works fine . But i want to send master report's parameter to detail at run time which is selected in master report, then i got an error

i want to use

http://marshad/ReportServer?/UpdatedByClickTest/S&rs:Command=Render&P1=" &Parameters!p1.Value& "

but an error come i,e

" The path of the item '/UpdatedByClickTest/S,Parameters!p1.Value, "' is not valid. The full path must be less than 260 characters long, must start with slash; other restrictions apply. Check the documentation for complete set of restrictions. (rsInvalidItemPath)"

how can i pass parameter to remove this error?

plz any one help me i shall be thankfull to you

Hello Arshad,

Where are you trying to generate the URL?

If you just want to display a link, this will append your parajmeter to the URL:

="http://marshad/ReportServer?/UpdatedByClickTest/S&rs:Command=Render&P1=" + cStr(Parameters!p1.Value)

Hope this helps.

Jarret

|||

Thanks Jarret its working now i m using

="http://marshad/ReportServer?/UpdatedByClickTest/S&rs:Command=Render&P1=" & Parameters!p1.Value

now i want to use global server name becuase i will have to deploy reports to different servers e,g DEV, QA and Production

i m using code like

=Globals!ReportServerUrl & "?/UpdatedByClickTest/S&rs:Command=Render&P1="&Parameters!p1.Value

but its not working plz send me ur code.

|||

That should work, but not while you are designing the report. I tried what you posted and it worked when I deployed the report. When you deploy it to the server and run it from there, you should see the ReportServerURL showing correctly.

Jarret

problem passing parameter to crystal from .net

I do this:

' Set the name of the parameter to modify.
paramField.ParameterFieldName = "P1"
' Set a value to the parameter.
paramValue.Value = strTemp
paramField.CurrentValues.Add(paramValue)
paramField.DefaultValues.Add(paramValue)
' Add the parameter to the ParameterFields collection.
paramFields.Add(paramField)
CrystalReportViewer.ParameterFieldInfo = paramFields
strReportSource = strReportSource & "Transaction For Specified Account.rpt"
CrystalReportViewer.ReportSource = strReportSource

But I get "Load reort failed".

Any suggestions...

Thanks....hi njuser,

if you get "load report failed" you do not have a problem with passing parameters, the report generator doesn't find the report!

when you call reportDocument.Load() it needs the path of the report like this: ( use the full path of the report-file )

"c:\\inetpub\\wwwroot\\reports\\myreport.rpt"

important are the "\\", the reportdocument class don't accept a single "\".

if you have problems with passing parameters you get a message like:
"current parameter-value missing"

cu,
tomcat

Problem passing parameter into remote stored proc

I'm having a problem passing a parameter value into a stored procedure
that I am running on a remote (linked) server, and am receiving a DTC
error because of it.
I have a stored procedure that brings in a variable (@.CustID int). I
later pass that parameter to another stored procedure. The code looks
like this...
EXEC LinkedServer.dbname.dbo.spname @.CustID
When I run that, I get this error...
Server: Msg 7391, Level 16, State 1, Procedure spname, Line 394
The operation could not be performed because the OLE DB provider
'SQLOLEDB' was unable to begin a distributed transaction.
OLE DB error trace [OLE/DB Provider 'SQLOLEDB'
ITransactionJoin::JoinTransaction returned 0x8004d00a].
[OLE/DB provider returned message: New transaction cannot enlist in the
specified transaction coordinator. ]
However, if I hard-code the parameter, it works:
EXEC LinkedServer.dbname.dbo.spname 1234 -- this works.
I can even do this:
DECLARE @.var int
SET @.var = 1234
EXEC LinkedServer.dbname.dbo.spname @.var -- this works too.
But if I accept the variable as an input parameter to my stored
procedure, I get the error listed above.
Any ideas?
Thanks in advance for your help...
Zev Steinhardtzev_steinhardt
what happen if you assign the parameter to a variable?
DECLARE @.var int
SET @.var = @.CustID
EXEC LinkedServer.dbname.dbo.spname @.var
...
AMB
"zev_steinhardt" wrote:

> I'm having a problem passing a parameter value into a stored procedure
> that I am running on a remote (linked) server, and am receiving a DTC
> error because of it.
> I have a stored procedure that brings in a variable (@.CustID int). I
> later pass that parameter to another stored procedure. The code looks
> like this...
> EXEC LinkedServer.dbname.dbo.spname @.CustID
> When I run that, I get this error...
> Server: Msg 7391, Level 16, State 1, Procedure spname, Line 394
> The operation could not be performed because the OLE DB provider
> 'SQLOLEDB' was unable to begin a distributed transaction.
> OLE DB error trace [OLE/DB Provider 'SQLOLEDB'
> ITransactionJoin::JoinTransaction returned 0x8004d00a].
> [OLE/DB provider returned message: New transaction cannot enlist in the
> specified transaction coordinator. ]
> However, if I hard-code the parameter, it works:
> EXEC LinkedServer.dbname.dbo.spname 1234 -- this works.
> I can even do this:
> DECLARE @.var int
> SET @.var = 1234
> EXEC LinkedServer.dbname.dbo.spname @.var -- this works too.
> But if I accept the variable as an input parameter to my stored
> procedure, I get the error listed above.
> Any ideas?
> Thanks in advance for your help...
> Zev Steinhardt
>|||Thanks for the reply, Alejandro.
I tried that. It didn't work.
I even tried to trick it into thinking that it's another variable
altogether. I put the variable into a temp table, declared a new
variable, populated it with the value from the temp table and passed it
in. That didn't work either.
Zev Steinhardt|||zev_steinhardt,
Are you executing the remote sp inside a transaction?
AMB
"zev_steinhardt" wrote:

> Thanks for the reply, Alejandro.
> I tried that. It didn't work.
> I even tried to trick it into thinking that it's another variable
> altogether. I put the variable into a temp table, declared a new
> variable, populated it with the value from the temp table and passed it
> in. That didn't work either.
> Zev Steinhardt
>|||Yes. The remote sp is within a transaction.
Zev|||zev_steinhardt,
you are using a distributed one, correct?
begin distributed transaction
exec ...
AMB
"zev_steinhardt" wrote:

> Yes. The remote sp is within a transaction.
> Zev
>|||Alejandro...
Yes, it is a distributed transaction... and I have XACT_ABORT on
Zev|||zev_steinhardt,
When you execute the remote sp using:
DECLARE @.var int
SET @.var = 1234
EXEC LinkedServer.dbname.dbo.spname @.var -- this works too.
then you are not executing it using a distributed transaction, that is why
you do not get the error.
See if this helps.
You receive error 7391 when you run a distributed transaction against a
linked server
http://support.microsoft.com/kb/329332/en-us
AMB
"zev_steinhardt" wrote:

> Alejandro...
> Yes, it is a distributed transaction... and I have XACT_ABORT on
> Zev
>

Problem passing parameter from VB.Net 2005 to crystal - code included

I am trying to pass a few parameters to crystal from vb.net 2005. Here is what I have, and it is not working. Everything else on the report works fine. Any ideas?

It is asking me to enter the value in a new window when the report loads..."You can provide a single value for this parameter. Enter the value you want to include........."

Dim strReportPath1 As String = "MainSummary"
Dim strConnection As String = "Data Source=localhost;Integrated Security=SSPI;" & _
"Initial Catalog=Carc2;"
Dim Connection As New SqlConnection(strConnection)
Dim strSQL As String = "My Select statement is here...too long to show in code"
Dim DA As New SqlDataAdapter(strSQL, Connection)
Dim DS As New DataSet

DA.Fill(DS, "SummaryInfo")

Dim strReportPath As String = Application.StartupPath & "\" & strReportPath1 & ".rpt"

If Not IO.File.Exists(strReportPath) Then
Throw (New Exception("Unable to locate report file:" & vbCrLf & strReportPath))
End If

If frmSummaryRpt.RadioShip.Checked = True Then
cr.SetParameterValue("ShipDate", frmSummaryRpt.txtStart.Text & " - " & frmSummaryRpt.txtEnd.Text)
ElseIf frmSummaryRpt.RadioShip.Checked = False Then
cr.SetParameterValue("ShipDate", "No ShipDate Selected")
End If

cr.Load(strReportPath)
cr.SetDataSource(DS.Tables("SummaryInfo"))This is resolved. The problem was that my if statements were before the report was loaded. I moved the area that they occured and it worked finesql

Problem passing columns as parameter!

Dear friens,

I need to pass a column as a parameter in my query. I did this:

ALTER PROCEDURE [dbo].[GD_SP_GET_UsersByDIR_COD]

@.Direccao nvarchar(11),

@.prmFieldName nvarchar(25),

@.prmFieldValue nvarchar(25)

AS

BEGIN

IF @.prmFieldValue='*' OR @.prmFieldValue=''

BEGIN

SELECT TOP (100) PERCENT dbo.ADServico_User.UserID, dbo.ADUser.UserName AS Nome, dbo.HARDWARE.New_Computername AS Computername,

dbo.ModeloPC.MOD_ModeloPC AS ModeloPC, dbo.Monitor.MON_Monitor AS Monitor, dbo.Status.StatusNome AS Status,

dbo.HARDWARE.Migrada AS Interven??o, dbo.HARDWARE.MigraViaChange AS [Migrada via Change], dbo.HARDWARE.StatusID,

dbo.HARDWARE.NS_ID

FROM dbo.ModeloPC INNER JOIN

dbo.SERVICO INNER JOIN

dbo.ADServico_User ON dbo.SERVICO.S_GrupoServico = dbo.ADServico_User.GrupoServico INNER JOIN

dbo.HARDWARE ON dbo.ADServico_User.UserID = dbo.HARDWARE.UserID INNER JOIN

dbo.Status ON dbo.HARDWARE.StatusID = dbo.Status.ID ON dbo.ModeloPC.MODELO_ID = dbo.HARDWARE.MODELO_ID INNER JOIN

dbo.Monitor ON dbo.HARDWARE.MONITOR_ID = dbo.Monitor.MONITOR_ID INNER JOIN

dbo.DIRECCAO ON dbo.SERVICO.S_NomeDir = dbo.DIRECCAO.DIR_COD LEFT OUTER JOIN

dbo.ADUser ON dbo.HARDWARE.UserID = dbo.ADUser.UserID

WHERE (dbo.HARDWARE.StatusID <> 6) AND (dbo.DIRECCAO.DIR_COD = @.Direccao)

ORDER BY Nome

END

ELSE

BEGIN

DECLARE @.SQL varchar(7000)

SET @.Direccao='CGD-DAS'

SET @.prmFieldName='UserID'

SET @.prmFieldValue='C095122'

SET @.SQL = 'SELECT

TOP (100) PERCENT dbo.ADServico_User.UserID, dbo.ADUser.UserName AS Nome, dbo.HARDWARE.New_Computername AS Computername,

dbo.ModeloPC.MOD_ModeloPC AS ModeloPC, dbo.Monitor.MON_Monitor AS Monitor, dbo.Status.StatusNome AS Status,

dbo.HARDWARE.Migrada AS Interven??o, dbo.HARDWARE.MigraViaChange AS [Migrada via Change], dbo.HARDWARE.StatusID,

dbo.HARDWARE.NS_ID

FROM dbo.ModeloPC INNER JOIN

dbo.SERVICO INNER JOIN

dbo.ADServico_User ON dbo.SERVICO.S_GrupoServico = dbo.ADServico_User.GrupoServico INNER JOIN

dbo.HARDWARE ON dbo.ADServico_User.UserID = dbo.HARDWARE.UserID INNER JOIN

dbo.Status ON dbo.HARDWARE.StatusID = dbo.Status.ID ON dbo.ModeloPC.MODELO_ID = dbo.HARDWARE.MODELO_ID INNER JOIN

dbo.Monitor ON dbo.HARDWARE.MONITOR_ID = dbo.Monitor.MONITOR_ID INNER JOIN

dbo.DIRECCAO ON dbo.SERVICO.S_NomeDir = dbo.DIRECCAO.DIR_COD LEFT OUTER JOIN

dbo.ADUser ON dbo.HARDWARE.UserID = dbo.ADUser.UserID

WHERE (dbo.HARDWARE.StatusID <> 6) AND (dbo.DIRECCAO.DIR_COD = @.Direccao)

AND '+ @.prmFieldName +' =' + @.prmFieldValue + ' '

EXEC @.SQL

END

END

THE COMAND EXECUTE SUCESSFULLY IN QUERY ANALISER, BUT IN ASP.NET 2.0 CLIENT RETURNS THE FOLLOWING ERROR:

Server Error in '/WS_GestaoDesktop' Application.


The name 'SELECT
TOP (100) PERCENT dbo.ADServico_User.UserID, dbo.ADUser.UserName AS Nome, dbo.HARDWARE.New_Computername AS Computername,
dbo.ModeloPC.MOD_ModeloPC AS ModeloPC, dbo.Monitor.MON_Monitor AS Monitor, dbo.Status.StatusNome AS Status,
dbo.HARDWARE.Migrada AS Interven??o, dbo.HARDWARE.MigraViaChange AS [Migrada via Change], dbo.HARDWARE.StatusID,
dbo.HARDWARE.NS_ID
FROM dbo.ModeloPC INNER JOIN
dbo.SERVICO INNER JOIN
dbo.ADServico_User ON dbo.SERVICO.S_GrupoServico = dbo.ADServico_User.GrupoServico INNER JOIN
dbo.HARDWARE ON dbo.ADServico_User.UserID = dbo.H' is not a valid identifier.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: The name 'SELECT
TOP (100) PERCENT dbo.ADServico_User.UserID, dbo.ADUser.UserName AS Nome, dbo.HARDWARE.New_Computername AS Computername,
dbo.ModeloPC.MOD_ModeloPC AS ModeloPC, dbo.Monitor.MON_Monitor AS Monitor, dbo.Status.StatusNome AS Status,
dbo.HARDWARE.Migrada AS Interven??o, dbo.HARDWARE.MigraViaChange AS [Migrada via Change], dbo.HARDWARE.StatusID,
dbo.HARDWARE.NS_ID
FROM dbo.ModeloPC INNER JOIN
dbo.SERVICO INNER JOIN
dbo.ADServico_User ON dbo.SERVICO.S_GrupoServico = dbo.ADServico_User.GrupoServico INNER JOIN
dbo.HARDWARE ON dbo.ADServico_User.UserID = dbo.H' is not a valid identifier.

Source Error:

Line 3269: }

Line 3270: dsHardware.dtGD_SP_GET_UsersByDIR_CODDataTable dataTable = new dsHardware.dtGD_SP_GET_UsersByDIR_CODDataTable();

Line 3271: this.Adapter.Fill(dataTable);

Line 3272: return dataTable;

Line 3273: }

The problem is based here:

WHERE (dbo.HARDWARE.StatusID <> 6) AND (dbo.DIRECCAO.DIR_COD = @.Direccao)

if you want to pass a static value use

WHERE (dbo.HARDWARE.StatusID <> 6) AND (dbo.DIRECCAO.DIR_COD = ''' + @.Direccao + ''')

if you want to pass a identifier use

WHERE (dbo.HARDWARE.StatusID <> 6) AND (dbo.DIRECCAO.DIR_COD = ' + @.Direccao + ')

HTh, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

Dear Friend,I changed as you told, but the error still there! :-(

CREATE PROCEDURE [dbo].[GD_SP_GET_UsersByDIR_COD]

@.Direccao nvarchar(11),

@.prmFieldName nvarchar(25),

@.prmFieldValue nvarchar(25)

AS

BEGIN

IF @.prmFieldValue='*' OR @.prmFieldValue=''

BEGIN

SELECT TOP (100) PERCENT dbo.ADServico_User.UserID, dbo.ADUser.UserName AS Nome, dbo.HARDWARE.New_Computername AS Computername,

dbo.ModeloPC.MOD_ModeloPC AS ModeloPC, dbo.Monitor.MON_Monitor AS Monitor, dbo.Status.StatusNome AS Status,

dbo.HARDWARE.Migrada AS Interven??o, dbo.HARDWARE.MigraViaChange AS [Migrada via Change], dbo.HARDWARE.StatusID,

dbo.HARDWARE.NS_ID

FROM dbo.ModeloPC INNER JOIN

dbo.SERVICO INNER JOIN

dbo.ADServico_User ON dbo.SERVICO.S_GrupoServico = dbo.ADServico_User.GrupoServico INNER JOIN

dbo.HARDWARE ON dbo.ADServico_User.UserID = dbo.HARDWARE.UserID INNER JOIN

dbo.Status ON dbo.HARDWARE.StatusID = dbo.Status.ID ON dbo.ModeloPC.MODELO_ID = dbo.HARDWARE.MODELO_ID INNER JOIN

dbo.Monitor ON dbo.HARDWARE.MONITOR_ID = dbo.Monitor.MONITOR_ID INNER JOIN

dbo.DIRECCAO ON dbo.SERVICO.S_NomeDir = dbo.DIRECCAO.DIR_COD LEFT OUTER JOIN

dbo.ADUser ON dbo.HARDWARE.UserID = dbo.ADUser.UserID

WHERE (dbo.HARDWARE.StatusID <> 6) AND (dbo.DIRECCAO.DIR_COD = @.Direccao)

ORDER BY Nome

END

ELSE

BEGIN

DECLARE @.SQL varchar(7000)

SET @.Direccao='CGD-DAS'

SET @.prmFieldName='UserID'

SET @.prmFieldValue='C095122'

SET @.SQL = 'SELECT

TOP (100) PERCENT dbo.ADServico_User.UserID, dbo.ADUser.UserName, dbo.HARDWARE.New_Computername,

dbo.ModeloPC.MOD_ModeloPC, dbo.Monitor.MON_Monitor AS Monitor, dbo.Status.StatusNome,

dbo.HARDWARE.Migrada, dbo.HARDWARE.MigraViaChange, dbo.HARDWARE.StatusID,

dbo.HARDWARE.NS_ID

FROM dbo.ModeloPC INNER JOIN

dbo.SERVICO INNER JOIN

dbo.ADServico_User ON dbo.SERVICO.S_GrupoServico = dbo.ADServico_User.GrupoServico INNER JOIN

dbo.HARDWARE ON dbo.ADServico_User.UserID = dbo.HARDWARE.UserID INNER JOIN

dbo.Status ON dbo.HARDWARE.StatusID = dbo.Status.ID ON dbo.ModeloPC.MODELO_ID = dbo.HARDWARE.MODELO_ID INNER JOIN

dbo.Monitor ON dbo.HARDWARE.MONITOR_ID = dbo.Monitor.MONITOR_ID INNER JOIN

dbo.DIRECCAO ON dbo.SERVICO.S_NomeDir = dbo.DIRECCAO.DIR_COD LEFT OUTER JOIN

dbo.ADUser ON dbo.HARDWARE.UserID = dbo.ADUser.UserID

WHERE (dbo.HARDWARE.StatusID <> 6) AND (dbo.DIRECCAO.DIR_COD ='+ @.Direccao +')

AND '+ @.prmFieldName +' =' + @.prmFieldValue + ' '

EXEC @.SQL

END

END

ERROR:

Msg 203, Level 16, State 2, Procedure GD_SP_GET_UsersByDIR_COD, Line 49

The name 'SELECT

TOP (100) PERCENT dbo.ADServico_User.UserID, dbo.ADUser.UserName AS Nome, dbo.HARDWARE.New_Computername AS Computername,

dbo.ModeloPC.MOD_ModeloPC AS ModeloPC, dbo.Monitor.MON_Monitor AS Monitor, dbo.Status.StatusNome AS Status,

dbo.HARDWARE.Migrada AS Interven??o, dbo.HARDWARE.MigraViaChange AS [Migrada via Change], dbo.HARDWARE.StatusID,

dbo.HARDWARE.NS_ID

FROM dbo.ModeloPC INNER JOIN

dbo.SERVICO INNER JOIN

dbo.ADServico_User ON dbo.SERVICO.S_GrupoServico = dbo.ADServico_User.GrupoServico INNER JOIN

dbo.HARDWARE ON dbo.ADServico_User.UserID = dbo.H' is not a valid identifier.

|||

change the following things..

CREATE PROCEDURE [dbo].[GD_SP_GET_UsersByDIR_COD]

@.Direccao nvarchar(11),

@.prmFieldName nvarchar(25),

@.prmFieldValue nvarchar(25)

AS

BEGIN

IF @.prmFieldValue='*' OR @.prmFieldValue=''

BEGIN

SELECT TOP (100) PERCENT dbo.ADServico_User.UserID, dbo.ADUser.UserName AS Nome, dbo.HARDWARE.New_Computername AS Computername,

dbo.ModeloPC.MOD_ModeloPC AS ModeloPC, dbo.Monitor.MON_Monitor AS Monitor, dbo.Status.StatusNome AS Status,

dbo.HARDWARE.Migrada AS Interven??o, dbo.HARDWARE.MigraViaChange AS [Migrada via Change], dbo.HARDWARE.StatusID,

dbo.HARDWARE.NS_ID

FROM dbo.ModeloPC INNER JOIN

dbo.SERVICO INNER JOIN

dbo.ADServico_User ON dbo.SERVICO.S_GrupoServico = dbo.ADServico_User.GrupoServico INNER JOIN

dbo.HARDWARE ON dbo.ADServico_User.UserID = dbo.HARDWARE.UserID INNER JOIN

dbo.Status ON dbo.HARDWARE.StatusID = dbo.Status.ID ON dbo.ModeloPC.MODELO_ID = dbo.HARDWARE.MODELO_ID INNER JOIN

dbo.Monitor ON dbo.HARDWARE.MONITOR_ID = dbo.Monitor.MONITOR_ID INNER JOIN

dbo.DIRECCAO ON dbo.SERVICO.S_NomeDir = dbo.DIRECCAO.DIR_COD LEFT OUTER JOIN

dbo.ADUser ON dbo.HARDWARE.UserID = dbo.ADUser.UserID

WHERE (dbo.HARDWARE.StatusID <> 6) AND (dbo.DIRECCAO.DIR_COD = @.Direccao)

ORDER BY Nome

END

ELSE

BEGIN

DECLARE @.SQL varchar(7000)

SET @.Direccao='CGD-DAS'

SET @.prmFieldName='UserID'

SET @.prmFieldValue='C095122'

SET @.SQL = 'SELECT

TOP (100) PERCENT dbo.ADServico_User.UserID, dbo.ADUser.UserName, dbo.HARDWARE.New_Computername,

dbo.ModeloPC.MOD_ModeloPC, dbo.Monitor.MON_Monitor AS Monitor, dbo.Status.StatusNome,

dbo.HARDWARE.Migrada, dbo.HARDWARE.MigraViaChange, dbo.HARDWARE.StatusID,

dbo.HARDWARE.NS_ID

FROM dbo.ModeloPC INNER JOIN

dbo.SERVICO INNER JOIN

dbo.ADServico_User ON dbo.SERVICO.S_GrupoServico = dbo.ADServico_User.GrupoServico INNER JOIN

dbo.HARDWARE ON dbo.ADServico_User.UserID = dbo.HARDWARE.UserID INNER JOIN

dbo.Status ON dbo.HARDWARE.StatusID = dbo.Status.ID ON dbo.ModeloPC.MODELO_ID = dbo.HARDWARE.MODELO_ID INNER JOIN

dbo.Monitor ON dbo.HARDWARE.MONITOR_ID = dbo.Monitor.MONITOR_ID INNER JOIN

dbo.DIRECCAO ON dbo.SERVICO.S_NomeDir = dbo.DIRECCAO.DIR_COD LEFT OUTER JOIN

dbo.ADUser ON dbo.HARDWARE.UserID = dbo.ADUser.UserID

WHERE (dbo.HARDWARE.StatusID <> 6) AND (dbo.DIRECCAO.DIR_COD ='''+ @.Direccao +''')

AND '+ @.prmFieldName +' =''' + @.prmFieldValue + ''' '

EXEC @.SQL

END

END

|||

Manid,

I changed as you told, but the error still there! :-(

Regards.

|||I guess you are either trying to change another procedure than you are executing or you will have to provide the whole snippet of code via mail or something to make it reproducable.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de|||

Dear Jens,

I created a more simple query, based in the same problem:

CREATE PROCEDURE TEMP

AS

DECLARE @.SQL varchar(8000)

DECLARE @.prmFieldName varchar(20)

DECLARE @.prmFieldValue varchar(20)

SET @.prmFieldName='UserID'

SET @.prmFieldValue='C095122'

SET @.SQL = 'SELECT New_Computername

FROM HARDWARE

WHERE '+ @.prmFieldName +' =''' + @.prmFieldValue + ''' '

EXEC @.SQL

The logical is the some of other queries, but in this one I can't executed it, because returns the following error:

Msg 2812, Level 16, State 62, Procedure TEMP, Line 15

Could not find stored procedure 'SELECT New_Computername

FROM HARDWARE

WHERE UserID ='C095122' '.

(1 row(s) affected)

If you can put this query with column parameter workink good, my problem probably is resolved for the other queries.

Thanks!

|||Sorry and blame on me for not seeing this, you will have to wriite the exec as follows:

EXEC(@.SQL)

HTH, jens K. Suessmeyer.

http://www.sqlserver2005.de|||

Dear friends,

I created a new simple query to try to resolve the problem of passing a column as parameter, using sp_executesql, but still return error. :-(

ALTER PROCEDURE TEMP

@.prmFieldName nvarchar(25),

@.prmFieldValue nvarchar(25)

AS

DECLARE @.SQL varchar(8000)

SET @.prmFieldName='UserID'

SET @.prmFieldValue='C095122'

SET @.SQL = N'SELECT New_Computername

FROM HARDWARE

WHERE '+ @.prmFieldName +' =''' + @.prmFieldValue + ''' '

EXECUTE sp_executesql @.SQL;

ERROR:

Msg 214, Level 16, State 2, Procedure sp_executesql, Line 1

Procedure expects parameter '@.statement' of type 'ntext/nchar/nvarchar'.

|||

Dear Friends,

I found the solution for my problem.

I must use EXECTUTE sp_executesql @.SQL in spite of EXEC @.SQL, and I must use nvarchar(4000) in spite of varchar(8000).

The final Result:

ALTER PROCEDURE [dbo].[GD_SP_GET_UsersByDIR_COD]

@.Direccao nvarchar(11),

@.prmFieldName nvarchar(30),

@.prmFieldValue nvarchar(25)

AS

BEGIN

IF @.prmFieldValue='*' OR @.prmFieldValue=''

BEGIN

SELECT TOP (100) PERCENT dbo.ADServico_User.UserID, dbo.ADUser.UserName AS Nome, dbo.HARDWARE.New_Computername AS Computername,

dbo.ModeloPC.MOD_ModeloPC AS ModeloPC, dbo.Monitor.MON_Monitor AS Monitor, dbo.Status.StatusNome AS Status,

dbo.HARDWARE.Migrada AS Interven??o, dbo.HARDWARE.MigraViaChange AS [Migrada via Change], dbo.HARDWARE.StatusID,

dbo.HARDWARE.NS_ID

FROM dbo.ModeloPC INNER JOIN

dbo.SERVICO INNER JOIN

dbo.ADServico_User ON dbo.SERVICO.S_GrupoServico = dbo.ADServico_User.GrupoServico INNER JOIN

dbo.HARDWARE ON dbo.ADServico_User.UserID = dbo.HARDWARE.UserID INNER JOIN

dbo.Status ON dbo.HARDWARE.StatusID = dbo.Status.ID ON dbo.ModeloPC.MODELO_ID = dbo.HARDWARE.MODELO_ID INNER JOIN

dbo.Monitor ON dbo.HARDWARE.MONITOR_ID = dbo.Monitor.MONITOR_ID INNER JOIN

dbo.DIRECCAO ON dbo.SERVICO.S_NomeDir = dbo.DIRECCAO.DIR_COD LEFT OUTER JOIN

dbo.ADUser ON dbo.HARDWARE.UserID = dbo.ADUser.UserID

WHERE (dbo.HARDWARE.StatusID <> 6) AND (dbo.DIRECCAO.DIR_COD = @.Direccao)

ORDER BY Nome

END

ELSE

BEGIN

DECLARE @.SQL nvarchar(4000)

SET @.SQL = N'SELECT

TOP (100) PERCENT dbo.ADServico_User.UserID, dbo.ADUser.UserName AS Nome, dbo.HARDWARE.New_Computername AS Computername,

dbo.ModeloPC.MOD_ModeloPC AS ModeloPC, dbo.Monitor.MON_Monitor AS Monitor, dbo.Status.StatusNome AS Status,

dbo.HARDWARE.Migrada AS Interven??o, dbo.HARDWARE.MigraViaChange AS [Migrada via Change], dbo.HARDWARE.StatusID,

dbo.HARDWARE.NS_ID

FROM dbo.ModeloPC INNER JOIN

dbo.SERVICO INNER JOIN

dbo.ADServico_User ON dbo.SERVICO.S_GrupoServico = dbo.ADServico_User.GrupoServico INNER JOIN

dbo.HARDWARE ON dbo.ADServico_User.UserID = dbo.HARDWARE.UserID INNER JOIN

dbo.Status ON dbo.HARDWARE.StatusID = dbo.Status.ID ON dbo.ModeloPC.MODELO_ID = dbo.HARDWARE.MODELO_ID INNER JOIN

dbo.Monitor ON dbo.HARDWARE.MONITOR_ID = dbo.Monitor.MONITOR_ID INNER JOIN

dbo.DIRECCAO ON dbo.SERVICO.S_NomeDir = dbo.DIRECCAO.DIR_COD LEFT OUTER JOIN

dbo.ADUser ON dbo.HARDWARE.UserID = dbo.ADUser.UserID

WHERE (dbo.HARDWARE.StatusID <> 6) AND (dbo.DIRECCAO.DIR_COD ='''+ @.Direccao +''')

AND '+ @.prmFieldName +' =''' + @.prmFieldValue + ''' '

EXECUTE sp_executesql @.SQL

END

END

THANKS FOR ALL YOUR IMPORTANT SUPPORT!!!

Problem passing a parameter in URL to a report

Hi all.
I have that problem. I need to pass a parameter to a report. That parameter
is a user in a windows domain, so I have the problem that is stored in
"DOMAIN\USER" format, and I can't pass the backslash to the url.
How can I solve that?
--
Regards,
Diego F.I ask myself. I can encode \ with %5C.
I'm embarrased for that stupid question...
--
Regards,
Diego F.
"Diego F." <diegofrNO@.terra.es> escribió en el mensaje
news:OUA34HxMGHA.344@.TK2MSFTNGP11.phx.gbl...
> Hi all.
> I have that problem. I need to pass a parameter to a report. That
> parameter is a user in a windows domain, so I have the problem that is
> stored in "DOMAIN\USER" format, and I can't pass the backslash to the url.
> How can I solve that?
> --
> Regards,
> Diego F.
>
>|||Also, you might not even need to do this. Look at the global variables in
the expression builder User!UserID, it is the user running the report.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Diego F." <diegofrNO@.terra.es> wrote in message
news:OTaydMxMGHA.720@.TK2MSFTNGP14.phx.gbl...
>I ask myself. I can encode \ with %5C.
> I'm embarrased for that stupid question...
> --
> Regards,
> Diego F.
>
> "Diego F." <diegofrNO@.terra.es> escribió en el mensaje
> news:OUA34HxMGHA.344@.TK2MSFTNGP11.phx.gbl...
>> Hi all.
>> I have that problem. I need to pass a parameter to a report. That
>> parameter is a user in a windows domain, so I have the problem that is
>> stored in "DOMAIN\USER" format, and I can't pass the backslash to the
>> url.
>> How can I solve that?
>> --
>> Regards,
>> Diego F.
>>
>|||... or you can use POST instead of GET. In other words, you can pass
parameters in a form instead of passing by querystring.

Tuesday, March 20, 2012

Problem On Store Report Parameter in Subscription ( by custom UI)

I wrote a interface on my website about create/update subscription .
when I get the parameter back by using GetReportParameters ()
the value was swap
for example:
I have 8 reportparameter: tcust, fcust, fdnnum, tdnnum, fdept, tdept, fairline, tairline.
all of them are string
when I create the subscription by:
tcust 1
fcust 2
fdnnum 3
tdnnum 4
fdept 5
tdept 6
fairline 7
tairline 8

then I get back that subscription
the value will be :
tcust 2

fcust 3

fdnnum 8

tdnnum 5

fdept 1

tdept 7

fairline 4

tairline 6

are there any order for storing the ReportParameter[] ?
thank youYou should not rely on order. ReportParameter has property Name which can be used to identify the parameter. See sample code at http://msdn2.microsoft.com/en-gb/library/microsoft.wssux.reportingserviceswebservice.rsmanagementservice2005.reportingservice2005.getreportparameters.aspx

Monday, February 20, 2012

Problem inserting sql query into database float datatype field using SQL Transaction

I have this problem of inserting my query into database field. My code is as of below.

The @.AVERAGESCORE parameter is derived from

Dim averagescore As Single = (122 * 1 + 159 * 2 + 18 * 3 + 3 * 4 + 0 * 5) / (122 + 159 + 18 + 3 + 0)

and the value returned is (averagescore.toString("0.00"))

However, I have error inserting the averagescore variable into a field of datatype float during the transaction. I have no problems when using non transactional sql insert methods. What could be the problem?

Try Dim iAs Integer For i = 0To arraySql.Count - 1 myCommand =New SqlCommandDim consolidatedobjitemAs ConsolidatedObjItem = arraySql(i) myCommand.CommandText = sqlStr myCommand.Connection = myConnection myCommand.Transaction = myTransWith myCommand.Parameters .Add(New SqlParameter("@.AVERAGESCORE", consolidatedobjitem.getaveragescore))End With myCommand.ExecuteNonQuery()Next myTrans.Commit() myConnection.Close()Catch exAs Exception Console.Write(ex.Message) myTrans.Rollback() myConnection.Close()End Try
 

In your code I did not where you creat the transaction. I use the code below, it works fine. I guess you shoul put the code in to a try catch block. if you want to use it

Dim averageAs Decimal = 1.23Dim mycommandAs SqlCommand =New SqlCommand()Dim myconnAs SqlConnection =New SqlConnection(ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ConnectionString) mycommand.CommandText ="Insert into Table1 values(1, @.Average)" myconn.Open() mycommand.Connection = myconnDim transAs SqlTransaction = myconn.BeginTransaction("new transaction") mycommand.Transaction = trans mycommand.Parameters.Add(New SqlParameter("@.Average", average)) mycommand.ExecuteNonQuery() mycommand.Transaction.Commit() mycommand.Connection.Close()
Hope this help|||

Thanks for replying. My problem lies with the equation I got my averagescore from.

Dim averagescoreAs Single = (122 * 1 + 159 * 2 + 18 * 3 + 3 * 4 + 0 * 5) / (122 + 159 + 18 + 3 + 0)average = average.toString("0.00)average =Decimal.Round(average, 2)average = Convert.toSingle(average)average = Math.round(average, 2)
I've in vain to convert the average score to a value which has 2 decimal places using various methods.
The value that I've gotten is 1.68. But I believe the value that is being inserted into the database is not that as I have
various errors. This is because I have tried hardcoding the inserted value like you did and it works.
Is there any other way to resolve this problem?
 
|||

The error that I've got most of the times are,

System.Data.SqlClient.SqlException: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 18 ("@.AVERAGESCORE"): The supplied value is not a valid instance of data type real. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

Hope this gives you a clearer idea, my guess is probably a rounding off error, but I just do not have any ideas left. I have even tried changing the database field datatype to decimal(10,2) to no effect.

|||

You could use SQL Server aggregate function Average with Decimal so you can set precision and scale. Try the link below for T-SQL Average aggregate function. Hope this helps.

http://msdn2.microsoft.com/en-us/library/ms173454.aspx

|||I afraid the AVG aggregate function woudn't help much in my case. Thanks anyway.|||

Can you print the type of averagescore. It might be become a decimal number after those manipulations, I do not think decimal can fit into float in sql server.

Hope this help

alienated:

The error that I've got most of the times are,

System.Data.SqlClient.SqlException: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 18 ("@.AVERAGESCORE"): The supplied value is not a valid instance of data type real. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision. at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

Hope this gives you a clearer idea, my guess is probably a rounding off error, but I just do not have any ideas left. I have even tried changing the database field datatype to decimal(10,2) to no effect.

|||Your error message is saying you are passing the wrong data type to the data protocol Tabular Data Stream. You have to convert Float to Decimal before passing it to SQL Server because there is only implicit conversion between Decimal and Numeric and Float and Real, any data passing between both pairs must be explict conversion. The reason is you can set precision and scale with the former and not the later. Hope this helps.