Showing posts with label related. Show all posts
Showing posts with label related. Show all posts

Friday, March 30, 2012

Inserting a blank line betwen groupings in my matrix report

I have a matrix report with 3 column groups. My main group is called
"Location" and then I dump out a bunch of data related to that location.
I want to insert a blank line before each new "Location" in my report but I
can't figure out how to do this with my matrix report.
Any ideas?Try putting this into expression for the location:
=(Fields!Location.Value+Environment.newline())
Good luck!
Peace,
Dan
"AdamB" <AdamB@.discussions.microsoft.com> wrote in message
news:6B279444-7502-43B3-B238-9C282A3C8858@.microsoft.com...
>I have a matrix report with 3 column groups. My main group is called
> "Location" and then I dump out a bunch of data related to that location.
> I want to insert a blank line before each new "Location" in my report but
> I
> can't figure out how to do this with my matrix report.
> Any ideas?

Monday, March 26, 2012

Insert values into 2 tables with one INSERT

Is this the appropriate way to insert information into a database with 2 tables (related with empID fields)

INSERT INTO table1
empID, first, last, dept, district
INSERT INTO table 2
className, classType, classDate

I am using ColdFusion to send the information to the database.

Thanks!Originally posted by helios76
Is this the appropriate way to insert information into a database with 2 tables (related with empID fields)

INSERT INTO table1
empID, first, last, dept, district
INSERT INTO table 2
className, classType, classDate

I am using ColdFusion to send the information to the database.

Thanks!

uhhhh...no

post the ddl for your tables...syntax is

INSERT INTO myTable (col1, col2, ect)
SELECT col1, col2, ect
FROM SomeOtherTable|||OK, full story of what I am trying to do.
Create a form that will go through ColdFusion to the database. This is how CFMX uses the SQL commands:

<cfquery name="AddEmployee" datasource="CompanyInfo">
INSERT INTO Employee
(Emp_ID,FirstName,LastName, Dept_ID,Contract)
VALUES (#Form.Emp_ID#,'#Form.FirstName#','#Form.LastName# ', #Form.Dept_ID#,'#Form.Contract#')
</cfquery>

The #Form.Emp_ID# is how CFMX knows what was entered on the HTML form and then sends it to the database.

What my goal is, is to send data to 2 tables that are linked by Emp_ID in the same database.|||Originally posted by helios76
OK, full story of what I am trying to do.
Create a form that will go through ColdFusion to the database. This is how CFMX uses the SQL commands:

<cfquery name="AddEmployee" datasource="CompanyInfo">
INSERT INTO Employee
(Emp_ID,FirstName,LastName, Dept_ID,Contract)
VALUES (#Form.Emp_ID#,'#Form.FirstName#','#Form.LastName# ', #Form.Dept_ID#,'#Form.Contract#')
</cfquery>

The #Form.Emp_ID# is how CFMX knows what was entered on the HTML form and then sends it to the database.

What my goal is, is to send data to 2 tables that are linked by Emp_ID in the same database.

You could add another insert in batch like this:

<cfquery name="AddEmployee" datasource="CompanyInfo">
INSERT INTO Employee
(Emp_ID,FirstName,LastName, Dept_ID,Contract)
VALUES (#Form.Emp_ID#,'#Form.FirstName#','#Form.LastName# ', #Form.Dept_ID#,'#Form.Contract#')
INSERT INTO Employee2
(Emp_ID,FirstName,LastName, Dept_ID,Contract)
VALUES (#Form.Emp_ID#,'#Form.FirstName#','#Form.LastName# ', #Form.Dept_ID#,'#Form.Contract#')
</cfquery>

Monday, March 19, 2012

Insert stored procedure for related tables

I have two sets of related tables: Quote - QuoteDetail and Order - OrderItem

I need to copy Quote - QuoteDetail records to Order - OrderItem tables

I have the stored procedure up to this point: Insert a Quote in the Order table and get the new Order @.@.Identity.

I need to insert the QuoteDetail records into the OrderItem table using the new OrderID

Thank you for your help.Thanks to all who looked!

I figured it out. I was trying to make it harder than it actually was.|||Hope this helps !


CREATE PROCEDURE [InsertTest]

AS

INSERT INTO tblPerson(Login,Password,Email,DateCreated)

VALUES('jaja','aaa','22@.yahoo.com','02-03-04')

INSERT INTO tblSnippet(CategoryID,PersonID,Title,Description,DateCreated)

VALUES(1,@.@.IDENTITY,'HAHA','This is good article',GETDATE());

GO

|||can u post the solution :)|||Here is the code you requested. I was having a mental block over the Select versus the VAULES() to put the @.OrderID into the new Item records. The simple solution is setting the@.OrderID AS OrderID in the SELECT statement.


CREATE PROCEDURE dbo.ECPO_Quote_Convert
(
@.QuoteIDint,
@.OrderIDint output
)
AS
INSERT INTO ECP_Order
(
UserID, ...
(rest of the fields)
)
SELECT
UserID, ...
(rest of the fields)
FROM
ECP_Quote
WHERE
QuoteID = @.QuoteID

SELECT @.OrderID = @.@.Identity

-- Insert QuoteDetail
INSERT INTO ECP_OrderItem
(
OrderID, ...
(rest of the fields)
)
SELECT
@.OrderID AS OrderID, ...
(rest of the fields)
FROM
ECP_QuoteDetail
WHERE
QuoteID = @.QuoteID AND Quantity > 0

Insert Statment not working

I know this is a sin in dbforums to jump forums to ask other forum questions, but I just had to do it....

it's actually related to foxpro dbf tables. Here is the case:

I am opening this existing DBF file in Microsoft Visual Fox Pro 6.0 .

In the command window, select, update and even including delete statements works .

What is getting on my nerves is the "insert" statement. It always prompts "syntax error". But the @.#$@.#$ error message just didn't help much.

The funny thing is, if I use the "Append Mode" and add data directly via the GUI, it works!.

Here is the insert statement, just a very simple one:

<code> INSERT INTO ASSET (ACCNO) values '2000/141'</code>

You can reply me here , or go to the real thread to reply me if you can help out..thanks

http://www.dbforums.com/t1058508.htmlINSERT INTO ASSET (ACCNO) values ('2000/141') ?|||Thanks! that work!!!......

Friday, February 24, 2012

Insert procedure in two tables with Foreign Key relation ship

I was wondering how I do to insert values in two tables that are related each other by a FK?

That is the procedure that illustrate what I meant to be.

ALTERProcedure [dbo].[new_user]

@.masternchar(10),

@.nicknchar(10),

@.fishnchar(10),

@.e_mailnchar(30)

As

Begin

INSERTINTO users

(nick, fish, e_mail)

VALUES (@.nick,@.fish,@.e_mail)

INSERTINTO friends

(user_id, e_mail)

VALUES (Selectuser_idfrom userswhere nick=@.master,@.e_mail)

End

Thank you very much.

ALTER Procedure [dbo].[new_user]@.masternchar(10),@.nicknchar(10),@.fishnchar(10),@.e_mailnchar(30)AsBeginSET NOCOUNT ONDeclare @.useridintINSERT INTO users (nick, fish, e_mail)VALUES (@.nick,@.fish,@.e_mail)SELECT @.userid = SCOPE_IDENTITY()INSERT INTO friends ([user_id], e_mail)VALUES (@.userid, @.e_mail)SET NOCOUNT OFFEnd
|||

Thanks to reply ndinakar.

The value inserted "@.userid" in friends table, it is not the same just inserted in the users table. This value is determined by a consult in users table, where nick = "@.master", the return of this consult will say which user_id I will insert in friends table.

|||So do you still need to do an INSERT into the users table with the values you receive in the stored proc or are the values just to be used for lookup?|||

The value @.master is for lookup the table users and gets the user_id. The values @.nick, @.fish, @.e_mail, are for create a new user. And is inserted a new record in friends table with user_id equals to the value consulted.

ALTERProcedure [dbo].[new_user]

@.masternchar(10),

@.nicknchar(10),

@.fishnchar(10),

@.e_mailnchar(30)

As

Begin

Declare@.returned_valuenchar(10)

Selectuser_idfrom userswhere nick=@.master

--I garante it will return a unique value. Supose to be called @.returned_value.

INSERTINTO users

(nick, fish, e_mail)

VALUES (@.nick,@.fish,@.e_mail)

INSERTINTO friends

(user_id, e_mail)

VALUES (@.returned_value,@.e_mail)

End

That will result a data base. Which the new user created will be related with the person who added.

|||
ALTER Procedure [dbo].[new_user]@.masternchar(10),@.nicknchar(10),@.fishnchar(10),@.e_mailnchar(30)AsBeginDeclare @.returned_valueint-- assuming userid is numeric if not I would recommend nvarchar instead of nchar.Select @.returned_value = [user_id]from userswhere nick=@.master--I garante it will return a unique value. Supose to be called @.returned_value.INSERT INTO users (nick, fish, e_mail)VALUES (@.nick,@.fish,@.e_mail)INSERT INTO friends ([user_id], e_mail)VALUES (@.returned_value,@.e_mail)End
|||Thank you very much indeed. But at last why you would recommend nvarchar instead of nchar?|||

When you use char, the length becomes a fixed size. So even if you send in a value less than the specified length, SQL pads the value with blank spaces to make it the fixed length.

So 'abc' <> 'abc '. Besides it is also a waste of space/memory. If you use varchar (Variable char) it allocates only as much is required, up to the specified length.

|||

On the select statement I mentioned that it will return a unique value, but if it return nothing or more fields?

If don't want waste your time explaining to me, could just give me the word that I look for on the internet? I tried some but I would never find about this problem specifically. And just wondering, do you know if Microsoft pays some one to stay here in this forum answering questions?

Thank you very much indeed.