Showing posts with label named. Show all posts
Showing posts with label named. Show all posts

Friday, March 30, 2012

OUTPUT - help with please

I am using a dynamic t-sql string in proc1 to execute proc2, which returns an int variable named @.Fatal_Error back to proc1.

When I execute proc2 I use the syntax:

EXEC @.SQL @.Params

@.SQL is the Proc Name (varchar) and @.Params is the parameter string (nvarchar).

If I include the @.Fatal_Error variable in the dynamic creation of the @.Params string the returning value from Proc2 is unable to convert int to nvarchar.

I have declared @.Fatal_Error in proc1 as int and tried to add to the end of my dynamic t-sql EXEC but I still get 'Cannot convert int to nvarchar' .

Please help - I'm beginning to pull out hair! :-)

Thanks!

Here' s the syntax I tried when just passing it at the end of the EXEC call:

EXEC @.SQL @.Param_List = @.Fatal_Error

AND I also tried:

EXEC @.SQL @.Param_List + ' '+@.Fatal_Error+' '

You have to use the sp_executesql for parameterized dynamic sql,

Code Snippet

Declare @.idParm as int;

Declare @.nameParm as varchar(100);

Declare @.dynamicSql as nvarchar(1000);

Declare @.dynamicParamDef as nvarchar(1000);

Set @.idParm = 2;

Set @.nameParm = 'sysobjects'

Set @.dynamicSql = N'Select * from sysobjects where id=@.id or name=@.name'

Set @.dynamicParamDef = N'@.id as int, @.name as varchar(100)'

Exec sp_executesql @.dynamicSql, @.dynamicParamDef, @.idParm, @.nameParm

|||

I quote from BOL(look for sp_executesql, building statement at runtime)

"

Transact-SQL supports the following methods of building SQL statements at run time in Transact-SQL scripts, stored procedures, and triggers:

Use the sp_executesql system stored procedure to execute a Unicode string. sp_executesql supports parameter substitution similar to the RAISERROR statement.

Use the EXECUTE statement to execute a character string. The EXECUTE statement does not support parameter substitution in the executed string."|||...and Manivannan prove it|||

Thank you all for your assistance. I will give it a whirl.

I was able to finally execute with EXEC @.SQL @.Params, @.Fatal_Error = @.Fatal_Error

However, I'm sure this will come back to bite me in the long run..

Thank you ALL for your quick replies!

|||

@.SQL is my stored procedure name

@.Param_List is the list of enumerated parameters

SET @.SQL = @.SQL + IsNull(@.Param_List,'');

EXECUTE sp_executesql @.SQL;

Worked like a charm.

Thanks!

Sandy

Monday, March 12, 2012

OSQL using named pipes instead of TCP/IP

Hi,
I'm having a small issue with OSQL. When I type "OSQL -S MYSERVER -E" , it
connects through TCP/IP, but on one client (that has DEVELOPER edition
installed), it tries to connect through Named Pipes, which is disabled for
the server that I'm trying to connect to. I checked the Client Config
Protocols and TCP/IP (2) is listed before Named Pipes (3).
I know I can prefix the server name with TCP: to force it to use TCP/IP,
but I don't want to do that. How can I get OSQL to connect through TCP/IP
instead of Named Pipes? Again the client has SQL 2005 Developer and the
Server has SQL 2005 Standard
Thanks!Found out. There was an alias for this server in there that told it to use
NP. Now to find out why there was an alias in there. . . . .
"Nieves" <JuanN@.yahoo.com> wrote in message
news:%238m7S8yPHHA.2312@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I'm having a small issue with OSQL. When I type "OSQL -S MYSERVER -E" ,
> it connects through TCP/IP, but on one client (that has DEVELOPER edition
> installed), it tries to connect through Named Pipes, which is disabled for
> the server that I'm trying to connect to. I checked the Client Config
> Protocols and TCP/IP (2) is listed before Named Pipes (3).
> I know I can prefix the server name with TCP: to force it to use TCP/IP,
> but I don't want to do that. How can I get OSQL to connect through TCP/IP
> instead of Named Pipes? Again the client has SQL 2005 Developer and the
> Server has SQL 2005 Standard
> Thanks!
>

Friday, March 9, 2012

OSQL using named pipes instead of TCP/IP

Hi,
I'm having a small issue with OSQL. When I type "OSQL -S MYSERVER -E" , it
connects through TCP/IP, but on one client (that has DEVELOPER edition
installed), it tries to connect through Named Pipes, which is disabled for
the server that I'm trying to connect to. I checked the Client Config
Protocols and TCP/IP (2) is listed before Named Pipes (3).
I know I can prefix the server name with TCP: to force it to use TCP/IP,
but I don't want to do that. How can I get OSQL to connect through TCP/IP
instead of Named Pipes? Again the client has SQL 2005 Developer and the
Server has SQL 2005 Standard
Thanks!
Found out. There was an alias for this server in there that told it to use
NP. Now to find out why there was an alias in there. . . . .
"Nieves" <JuanN@.yahoo.com> wrote in message
news:%238m7S8yPHHA.2312@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I'm having a small issue with OSQL. When I type "OSQL -S MYSERVER -E" ,
> it connects through TCP/IP, but on one client (that has DEVELOPER edition
> installed), it tries to connect through Named Pipes, which is disabled for
> the server that I'm trying to connect to. I checked the Client Config
> Protocols and TCP/IP (2) is listed before Named Pipes (3).
> I know I can prefix the server name with TCP: to force it to use TCP/IP,
> but I don't want to do that. How can I get OSQL to connect through TCP/IP
> instead of Named Pipes? Again the client has SQL 2005 Developer and the
> Server has SQL 2005 Standard
> Thanks!
>

OSQL using named pipes instead of TCP/IP

Hi,
I'm having a small issue with OSQL. When I type "OSQL -S MYSERVER -E" , it
connects through TCP/IP, but on one client (that has DEVELOPER edition
installed), it tries to connect through Named Pipes, which is disabled for
the server that I'm trying to connect to. I checked the Client Config
Protocols and TCP/IP (2) is listed before Named Pipes (3).
I know I can prefix the server name with TCP: to force it to use TCP/IP,
but I don't want to do that. How can I get OSQL to connect through TCP/IP
instead of Named Pipes? Again the client has SQL 2005 Developer and the
Server has SQL 2005 Standard
Thanks!Found out. There was an alias for this server in there that told it to use
NP. Now to find out why there was an alias in there. . . . .
"Nieves" <JuanN@.yahoo.com> wrote in message
news:%238m7S8yPHHA.2312@.TK2MSFTNGP04.phx.gbl...
> Hi,
> I'm having a small issue with OSQL. When I type "OSQL -S MYSERVER -E" ,
> it connects through TCP/IP, but on one client (that has DEVELOPER edition
> installed), it tries to connect through Named Pipes, which is disabled for
> the server that I'm trying to connect to. I checked the Client Config
> Protocols and TCP/IP (2) is listed before Named Pipes (3).
> I know I can prefix the server name with TCP: to force it to use TCP/IP,
> but I don't want to do that. How can I get OSQL to connect through TCP/IP
> instead of Named Pipes? Again the client has SQL 2005 Developer and the
> Server has SQL 2005 Standard
> Thanks!
>