|
Since I don't know the wholse situation, just throwing some ideas:
- Can you put the data into an xml format and in the subquery use xquery to fetch the data again
- if you're inserting data into the database using this IN operator, you could use arrays to pass the data to a procedure
- if you're selecting data you can do the same and then return ref cursor
- possibly you could use UDT's in the above scenarios
- you could create a function as pipelined, pass the data to that with an array and then use the return value of the function as a table in your subquery etc.
|
|
|
|
|
Thanks again.
I'll have a deeper look into this tomorrow. Eventually with another question...
|
|
|
|
|
hi
i have a update trigger that get fired when any column updated of the table
create TRIGGER trigger_Update_ABC
ON ABC
FOR Update
AS
declare @Id bigint
set @Id = (select Id from Inserted)
update ABC set ABC.Post = getdate() where Id =@Id
when i execute such sql quarry
Update ABC set ABC.Active = 1 where ABC.Id in(1,4,5,6,3,7)
then i got error
|
|
|
|
|
Triggers must *always* be written with the expectation that multiple rows will be affected. So SELECT ID from Inserted could return a series of INT not just one.
CREATETRIGGER trigger_Update_ABC ON ABC
FOR Update AS
UPDATE ABC
SET ABC.Post = GetDate()
WHERE ABC.ID IN (SELECT ID from inserted)
You should check to see if recursive triggers are set on your server, as this is an update trigger on ABC that updates ABC. If recursive triggers are enabled it could cause an infinite loop and the statement will fail.
Do some research into recursive triggers if this is enabled.
'Howard
|
|
|
|
|
than x Richards
my confusion is now much clear now
|
|
|
|
|
Full-text index tab is disabled and
I can only see partition schemes and partition functions under storage.
Help me out in this regard.
|
|
|
|
|
|
i got a procedure in SQL Server at the end of the program i write this code
SELECT @@IDENTITY
COMMIT TRANSACTION INSERT_NOMENCLATURE
RETURN
the problem that i don't have the column name of SELECT @@IDENTITY how can i manage it to get the value with a column name
thanks!
|
|
|
|
|
papy-boom wrote: i don't have the column name of SELECT @@IDENTITY how can i manage it to get the value with a column name
You don't know from which column @@IDENTITY returns the value. It just returns the last inserted identity value in your sesion. It can be any table and any identity column.
You can narrow the possibilities using SCOPE_IDENTITY, but you'd still face the same problem.
Normally you know where @@IDENTITY comes from in your procedure since it's the previous insert to identity columned table. What's the cause in your case that prevents you identifying the statement (and after that the table and the column)?
|
|
|
|
|
you mean if i replaced by select max from my table it will works?
|
|
|
|
|
papy-boom wrote: you mean if i replaced by select max from my table it will works?
No, that's not what I mean.
Since you didn't post any code or any explanation why do you want to know the column name, I can't say what's the answer for you.
Consider that I have a table:
CREATE TABLE Artist (
[Artist#] int NOT NULL IDENTITY(1,1) PRIMARY KEY,
[Name] nvarchar(100) NOT NULL
);
Then when I'm executing this piece of statement:
INSERT INTO Artist ([Name]) VALUES (@name);
SET @artistIdentity= @@IDENTITY;
Now on the 2'nd line I know that @@IDENTITY returns a value that is assigned to Artist# column in Artist table since that's the previous INSERT statement to a table that has an identity column.
|
|
|
|
|
the problem that is that in code part i have a datareader to read the value returned value and the argument to pass to datareader is the name of the column so if my procedure return me a value without the name of column it's not simple to get the value so i tried to get select @@IDENTITY AS returnedvalue to get the name of column but it doesn't work
|
|
|
|
|
papy-boom wrote: tried to get select @@IDENTITY AS returnedvalue to get the name of column but it doesn't work
No, because it only returns the value.
papy-boom wrote: i have a datareader to read the value returned value and the argument to pass to datareader is the name of the column so if my procedure return me a value without the name of column it's not simple to get the value
Now I don't follow the logic. You cannot ask the last added value for a single column using @@IDENTITY. It doesn't work that way.
If you need to know what's the last added identity value to a specific table, you can select MAX from the identity column. But I don't see the point why you should do this since the value of an identity column is normally irrelevant. Refer to: http://en.wikipedia.org/wiki/Surrogate_key[^]
So the question is, why do you wan't to know the value at all?
|
|
|
|
|
when i excute my procedure In SQL i have the value but in the name of column i have (no column name)
i write a script in C# to get the value with data reader but the method used in datareder is GetValueParam(Command,columName) the procedure dosen't return a name for this column i tried to give a name to returned column so i modify it with
COMMIT TRANSACTION INSERT_Artist
RETURN SELECT max(Artist#) AS ArtistId from Artist
LBL_ERROR:
ROLLBACK TRANSACTION INSERT_Artist
but i have the same problem (no column name) for returned value i need the column name to read it with a datareader without using another transaction
excuse my ignorance but i'm really dump in SQL Server
|
|
|
|
|
papy-boom wrote: the method used in datareder is GetValueParam(Command,columName) the procedure dosen't return a name for this column
Okay, now I understand your problem. You can give the column a name or rename a column in a result set using AS, like:
SELECT @@IDENTITY AS SomeColumnName
|
|
|
|
|
i've tried that but still not working
|
|
|
|
|
Try
Select @@Identity ID
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
In what respect is it not working?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
it works it was a problem in my Program
thank you all !!
|
|
|
|
|
Hi,
I am trying to pass an UPDATE / INSERT statement into an MS-SQL DB via a BAT script. Basically, I want to amend / add entries in the DB via a BAT script.
1. Can this be done?
2. If it can be done, how would I connect to the DB? What would the syntax be?
Any assistance on this will be much appreciated.
Thanks,
M
|
|
|
|
|
|
Thanks for your response Colin, much appreciated.
However, it looks like SQLCMD is only available in MS-SQL 2005 onwards. I am using MS-SQL 2000 though, and I think the OSQL command is the alternative.
Any experience with this?
Thanks!
|
|
|
|
|
mil_an wrote: I think the OSQL command is the alternative
Correct. The server & connection details can go on the command line and you can read a file of commands to execute. A quick google should reveal plenty of examples.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Thanks.
This is what I have so far and it seems to work when run on the server where the DB is located:
OSQL -s <<SERVER_NAME>>\<<DB_NAME>> -U <<USERNAME>> -P <<PASSWORD>> -i <<PATH_TO_SQL_COMMAND_FILE>>
The above makes the connection to the DB and runs the SQL statements held in a text file (PATH_TO_SQL_COMMAND_FILE), which looks a little like this:
UPDATE <<TABLE_NAME>>
SET <<Column>> = '<<VALUE>>'
WHERE <<PREDICTAES>>
GO
Now, I am facing the following issue. I am unable to run this command from a different server that does not host the DB. I get the below error:
[Shared Memory]SQL Server does not exist or access denied.<br />
[Shared Memory]ConnectionOpen (Connect()).
I am using the host name of the DB server including DNS for server_name.
Any ideas?
modified on Wednesday, December 10, 2008 9:15 AM
|
|
|
|