Showing posts with label instead. Show all posts
Showing posts with label instead. Show all posts

Friday, March 30, 2012

OUTPUT Clause

We have a table, which is partitioned on a computed column, based on a UDF function (custom logic). We populate this computed column in an INSTEAD OF Trigger. But when we try to "output" the computed column using OUTPUT caluse, NULL values are returned for computed column. SQL BOL is not clear on this part of using output clause in instead of triggers. This does not even work for a table that is not partitioned. Here is an example of what we are trying to do...

I would appreciate any help on this...

IF OBJECT_ID('dbo.Test') IS NOT NULL

DROP TABLE dbo.Test

GO

CREATE TABLE dbo.Test

( IdCol INT IDENTITY(1,1) NOT NULL,

Date DATETIME NOT NULL,

CalcCol CHAR(10) NOT NULL

)

GO

CREATE TRIGGER trgTest_InsUpd ON dbo.Test

INSTEAD OF INSERT AS

BEGIN

INSERT INTO dbo.Test

( Date, CalcCol ) SELECT Date, CONVERT(CHAR(10), Date, 101) FROM INSERTED

END

GO

IF OBJECT_ID('tempdb..#tmp') IS NOT NULL

DROP TABLE #tmp

GO

CREATE TABLE #tmp(IdCol INT, Date DATETIME, CalcCol VARCHAR(10))

TRUNCATE TABLE #tmp

INSERT INTO dbo.Test(Date) OUTPUT INSERTED.IdCol, INSERTED.Date, INSERTED.CalcCol INTO #tmp

VALUES(GETDATE())

--Here the identity and Computed column are returned as NULL

SELECT * FROM #tmp

SELECT * FROM dbo.Test

Instead of trigger would not have data in INSERTED and DELETED tables, because instead of the original insert statement your INSTEAD OF tRIGGER is getting fired. The tables will be populated if you write a AFTER TRIGGER.

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!
>

Wednesday, March 7, 2012

osql in a cmd file, with SQL statements coming from the same cmd f

I want to run osql in a command file. Instead of having the SQL statements
in a separate .sql file, using "osql -i file.sql..." I want to have the SQL
statements right there in the command file. This way my command file is
self-contained; only one file to worry about instead of separate cmd and sql
files.
In unix (or more precisely in the bash shell) this would be done by what is
called a "here document". Conceptually:
osql <<END_OF_SQL
select * from customers
select * from suppliers
END_OF_SQL
Any way to do this with OSQL, or by some CMD.EXE trick?
forestial wrote:
> I want to run osql in a command file. Instead of having the SQL
> statements in a separate .sql file, using "osql -i file.sql..." I
> want to have the SQL statements right there in the command file.
> This way my command file is self-contained; only one file to worry
> about instead of separate cmd and sql files.
> In unix (or more precisely in the bash shell) this would be done by
> what is called a "here document". Conceptually:
> osql <<END_OF_SQL
> select * from customers
> select * from suppliers
> END_OF_SQL
> Any way to do this with OSQL, or by some CMD.EXE trick?
Sure. You can create a CMD file to run the batch with contents like
this: Substitute -E to use a trusted connection which is recommended
over putting user id and password in the file. Use a capital Q to exit
OSQL immediately. Separate batches with Go and use -O for an output
file.
osql -Uuser -Ppassword (or -E) -Sserver -Q"Select id from sysobjects go
select id from sysindexes" -ooutput.txt
David Gugick
Imceda Software
www.imceda.com