|
Hi frends
I have written a trigger in MS-SQL 2000 runing successfully to insert single row.....but if i need to insert multiple rows from a select query in this trigger ......I am Confused ?
Purpose of Trigger
whenever a column will be updated in a table the data from two tables will be inserted into two tables where one table has multiple rows to insert.
I am trying to use While loop but confused that what should be the condition there to break tha loop......pls help if someone knows.
My trigger is
IF (COLUMNS_UPDATED() ) > 49
BEGIN
Declare @ServerDate datetime;
Declare @TranID numeric(18,0);
Declare @OppID numeric(18,0);
Declare @ProductID int;
Declare @Qty int;
Declare @Cost numeric(18,2);
Declare @Price numeric(18,2);
Declare @Discount numeric(18,2);
Declare @TaxAmt numeric(18,2);
Declare @UserID numeric(18,0);
Declare @ContactID numeric(18,0)
Declare @CountProduct int
SELECT @ServerDate=getdate()
SELECT @OppID=Opp.OppId, @ContactID=Opp.ContactID, @UserID=Opp.UserID FROM Opportunity Opp INNER JOIN INSERTED ON Opp.OppId = INSERTED.OppId where Inserted.StatusID=3
if (Convert(varchar(10),@OppID) != '')
BEGIN
INSERT INTO [Transaction] (OppID,TranDate, ContactID,UserID) values (@OppId, @ServerDate, @ContactID, @UserID)
SELECT @TranID=TranID from [Transaction] where TranDate=@ServerDate
SELECT @ProductID=Opp.ProductID, @Qty=Opp.Qty, @Cost=Opp.Cost, @Price=Opp.Price, @Discount=Opp.Discount, @TaxAmt=Opp.TaxAmt FROM vOpportunityList Opp INNER JOIN INSERTED ON Opp.OppId = INSERTED.OppId where Inserted.StatusID=3
--Count row
SELECT @CountProduct=count(Opp.ProductID) FROM vOpportunityList Opp INNER JOIN INSERTED ON Opp.OppId = INSERTED.OppId where Inserted.StatusID=3
--WHILE (-----------)
--BEGIN
INSERT INTO [TranProduct] (TranID,ProductID,Qty,Cost,Price,Discount,TaxAmt) values(@TranID, @ProductID, @Qty, @Cost, @Price, @Discount, @TaxAmt)
--END
END
END
Dinesh Sharma
|
|
|
|
|
I would suggest a cursor but using a cursor in a trigger is bad practice as it will be slow. Is there no way to do this update from your application inside of commitment control? If a trigger is your only option then use a cursor to do the loop. You don't need a row count variable either just loop through the results of your select statement. Check Here
for more info.
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
Thanks ToddHileHoffer
I done this and now its working properly...
Thanks a lot
Dinesh Sharma
Dinesh Sharma
|
|
|
|
|
Hi all,
Well first of all, I would like to know if it is possible to put sql scripting in a batch file for execution?
I can connect to the MySql Server with a batch file but can't execute anymore commands (MySql command like reading from a file). I don't know how to do this, so If anyone could point me to a site or help me .... well just thanx in advance
Regards
Programm3r
|
|
|
|
|
Hi all,
Well first of all, I would like to know if it is possible to put sql scripting in a batch file for execution?
I can connect to the MySql Server with a batch file but can't execute anymore commands (MySql command like reading from a file). I don't know how to do this, so If anyone could point me to a site or help me .... well just thanx in advance
Regards
Programm3r
|
|
|
|
|
You can use the osql command to execute the sql commands from the batch fils.
thanks,
SeEa
|
|
|
|
|
Hi everyone!
I have an Access table made up of various "ingredients". From this table by selecting various "ingredients" i want to create another table (or just create new entries in another table) of "recipe" names and store this table in the same or another Access file.
I am connecting to the ingredients table and filling a dataset with it, through a DataAdapter, then i'm displaying the contents in a DataGrid in which i've added a CheckBox column. I'm planning to use this checkbox column to select the ingredients for the various recipes.
I know i can link such tables by using a column in the ingredients table which will specify a recipe name for each ingredient. However my problem is that some of the recipes will share the same ingredients so i can't use such a column to create the relationship.
Any ideas on the way to tackle this problem?
Thanks in advance.
george
|
|
|
|
|
I get this message when running an application from a remote computer with standard connection.
SELECT permission denied on object 'custGroups', database 'ValkyriaDB', schema 'dbo'
I have SQL 2005 express database and MS SQL server managament studio express.
I done this so far:
In the security - logins - 'USER' - properties i have mapped my username to the correct db (default db) and in user mappings for that db i have granted all database roles to my username. The default scheme is dbo.
For the valkyriaDB schemes - dbo i have granted (Grant and With Grant) all permissions.
I simply dont understand why i get this error message... Must be something i dont understand.
Please advice
PS. It is much easier with old MSDN, or any opensource DB, dont understand why it has to be so hard with MS.
|
|
|
|
|
ITs not hard with MS it just enforces strong security.
Check you can access the object through a query using the 'USER' and debug from there. You might want to specifiy the db in your connection string as well as speficing the instance name mymachine\SQLEXPRESS
Look where you want to go not where you don't want to crash.
Bikers Bible
|
|
|
|
|
Thx, it helped, but now i got a new problem. Now it suddenly says:
System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
But still i can do connection.Open() from remote, i just can execute any statements. Where can i check if the server is set to receive remote connections?
BTW, my connection String:
="Server=MACHINENAME\SQLEXPRESS;Database=ValkyriaDB;UserID=XXXX;Password=XXX;Trusted_Connection=False;"
Thx for previous anserw, im new to SQL2005 or any MS database...
-- modified at 5:06 Tuesday 1st August, 2006
|
|
|
|
|
You are not using integrated windows security. Make sure that the SQL LogIn is a user in the db_datareader role in the database and you should be good to go.
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
How to return first 10 rows in a table using the select command in SQL?
|
|
|
|
|
SELECT TOP [rownumber] [col1][, col2]...
FROM [table]
e.g. SELECT TOP 10 name FROM tblNames
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
you can use order by to select on a defined order of a column
<br />
select Top 10 * from table<br />
order by created_date <br />
Look where you want to go not where you don't want to crash.
Bikers Bible
|
|
|
|
|
SELECT * FROM table where ROWNUM < 10 ORACLE
SELECT TOP 10 * FROM table SQL Server
SELECT * FROM table LIMIT 10 MySql Also
SELECT * FROM table LIMIT 10 OFFSET 50
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
i am trying to write a script. i need to copy the contents of my clipboard into a text file. then i need to save the text file as a htm file extention with a different name then i need to close both of the files. basically what i am doing is saving web page code in a filemaker pro data base. and i want to take the contents of a field that contains my code. and save itr as a htm file. is there any scripting language that will allow me to do this.
thanks in advance for any responses
|
|
|
|
|
Try APS.NET, Windows, C# or VB
Look where you want to go not where you don't want to crash.
Bikers Bible
|
|
|
|
|
weelze wrote: is this the right forum
Not really
weelze wrote: basically what i am doing is saving web page code in a filemaker pro data base. and i want to take the contents of a field that contains my code. and save itr as a htm file.
Sure, shouldn't be terible difficult with a scripting language such as VBS (Visual basic Scripting), the MSDN has a bunch of examples.
Visual Basic Scripting[^]
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
I want to add a new row to my datatable,then set this row is Currentrow
in BindingContext, so i change the BindingContext.Position for moving to the new row.
I have two forms,I can change the "BindingContext[mydatatable].Position" in one form ,but this cannot be implemented in another form .Who can tell me why?The code is:
DataRow dr = GdtKeyPoint.NewRow();
GdtKeyPoint.Rows.Add(dr);
this.BindingContext[GdtKeyPoint].Position = GdtKeyPoint.Rows.Count;
//or this.BindingContext[GdtKeyPoint].Position = GdtKeyPoint.Rows.Count-1;
//also can`t be implement. no error was raising!!
|
|
|
|
|
Are you using .Net 2.0? If yes, then try using BindingSource instead.
If not, then try working with the CurrencyManager instead of the BindingContext.
[edit]You can get the CurrencyManager from the BindingContext, and that's supposed to be the object that you edit instead./edit]
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia Last modified: Tuesday, 1 August 2006 01:32:54 --
|
|
|
|
|
To Edbert:
Thank you very much,I am using .net 2.0. but I just a freshman for it. I will try the method your words concerned .My English is poor, but I hope you'll understand what I said.
|
|
|
|
|
Hi,
using C#;
using VS2005;
I have a dataset that contains several datatables. What I wish to do is search each row in one of the tables and read/copy the value of a column into a variable. I will then manipulate the variable as needed. Specifically, the dataTable is "MembershipDetails" and the column is "MembershipNumber". The dataset is called "myclubDataSet".
The purpose of all this is to determine the next sequential membership number.
If someone could be so good enough to write the code for me I would very much appreciate it because I can't find a simple straightforward example anywhere on the net to learn from.
I know how to do a sql command to do this but I don't want to do it on the database. I wish to achieve it using the dataset.
Thanks in advance.
Glen Harvy
|
|
|
|
|
This seems a very hard way to do a simple task.
Run following sql code to get a last membership number
<br />
select top 1 MembershipNumber<br />
from myclubDataSet<br />
ORDER BY MembershipNumber DESC<br />
This will no however stop two user from trying to create the same membership number after getting the same last number from the database.
What you really want to do is return the membership number after creation
Make 'MembershipNumber' and identity column on your database and use similar codeas below,
<br />
insert membername, memberdetails<br />
VALUES ('Joe Bloggs', '15 Anyplace Road')<br />
<br />
SELECT @@Indentity<br />
<br />
The select @@Indentity will get the newly created memebership number. Try it in SQL before you try and code it.
Look where you want to go not where you don't want to crash.
Bikers Bible
|
|
|
|
|
Thanks for your asistance - much appreciated.
Frank Kerrigan wrote: This seems a very hard way to do a simple task.
That seems to be the way I do everything nowadays .
I have some database/SQL experience with designing websites that use databases and understand your suggestions pretty well BUT I need to achieve my aim without going back to the database. I really want to learn how to retrieve the value of a column in each row or specific row.
With a bit of help from elsewhere I've got as far as:-
DataTable table = myclubDataSet.Tables["MemberDetails"];
DataRow[] foundRows;
foundRows = table.Select("MembershipNumber > 1 ");
for (int i = 0; i < foundRows.Length; i++)
{
int num = System.Convert.ToInt32(foundRows["MembershipNumber"]);
MessageBox.Show("Membership number is: " + num);
}
But this leads to a build error message:
Error Cannot implicitly convert type 'string' to 'int'
with the culprit being MembershipNumber even though that column is defined as an Int32 in the datatable.
I hope you can see what I'm trying to learn to do and can just help me over this hurdle
Thanks,
Glen Harvy
|
|
|
|
|