Showing posts with label order. Show all posts
Showing posts with label order. Show all posts

Monday, March 19, 2012

make procedure to check balance > or < totalcost

helo all...,

i have create procedure can decreasetotalcost from order table(database:games.dbo) withbalance in bill table(database:bank.dbo). my 2 database in same server is name "boy"

i have 2 database like: bank.dbo and games.dbo

in games.dbo, have a table name is order(user_id,no_order,date,totalcost)

in bank.dbo, have a table name like is bill(no_bill,balance)

this is a list of bill table

no_bill balance

111222 200$

222444 10$

this is a list of order table

user_id no_order date totalcost

a 1 1/1/07 50$

when customer insert no_bill(111222) in page and click a button, then bill table became

no_bill balance

111222 150$

222444 10$

when customer insert no_bill(222444) in page and click a button, then message "sorry, your balance is not enough"


mystore procedure like:

ALTER PROCEDURE [dbo].[pay]
(
@.no_bill AS INT,
@.no_order AS int,
@.totalcost AS money
)
AS
BEGIN
BEGIN TRANSACTION

DECLARE @.balanc AS money


SET @.balanc= (SELECT [balance] FROM Bank.dbo.bill WHERE [no_bill] = @.no_bill)

UPDATE [bank.dbo.bill]
SET
[balance] = @.balanc - @.totalcost
WHERE
[no_bill] = @.no_bill

COMMIT TRANSACTION
END

it can decrease money in bank, but i want it ceck money if balance > totalcost, so balance-totalcost,

if balance<totalcost,so error message"sorry, your balance not enough"

is it can make in procedure?

thx...

Try this:

ALTER PROCEDURE [bank].[dbo].[pay]( @.no_billINT, @.no_orderint, @.totalcostmoney, @.messagevarchar(100)-- make it output parameter in your stored procedure)ASBEGIN TRANSACTION DECLARE @.balancAS moneyselect @.balance = balancefrom bank.dbo.billwhere no_bill = @.no_billselect @.totalcost = totalcostfrom games.dbo.totalcostwhere no_order = @.no_orderif (@.balance > @.totalcost)beginset @.balance = @.balance - @.totalcostUPDATE bank.dbo.billSET [balance] = @.balanceWHERE [no_bill] = @.no_bill-- set @.message = 'your have enough balance'endelsebeginset @.message ='sorry, your balance not enough'endCOMMIT TRANSACTIONset nocount off

Good luck.

|||

thx...

ur code is not display message. when i execute ur store procedure, it display:

type direction name value

int in no_bill we insert to this,ex:110

int in no_order we insert to this,ex:2

money in totalcost we insert to this, ex 100$

char in message ??? if i not insert to this, my error :Procedure or Function 'pay' expects parameter '@.message', which was not supplied.

so it must to insert it, but my purpose is display message automatic. how can i change direction to be output?

can u add output code to stroreprocedure?

pls..,thx...

Monday, March 12, 2012

Major Time Out Issue

I have created a database with three tables. The database has been up for a month now and contains about 20,000 records. In order to improve performance and resolve some issues I an attempting to change some of the table information. i.e. allow nulls in a few fields. When I use TSQL or the GUI to make these changes I get the following error: Timeout expired. The timeout period elapsed prior to completion of the operation or server not responding.

Source: .Net SQLClient Data Provider

I have SQL Server Express SP2 installed with .Net framework v3.0

Note: This issue appears when I attempt to delete a row from a table as well.

Any thoughts?

It is difficult to guess -there isn't enough information.

If users are in the database at the same time as you are attempting to make table wide changes, you could be experiencing 'blocking' behavior. Try making your changes when there are no users in the database. (Twenty thousand records is a very small table and most changes should happen relatively quickly.)

You might also verify the indexing.

Wednesday, March 7, 2012

MaintenancePlan - task order

Hello,
I created one maintenance plan with one schedule, it includes several
tasks. How I can change order on with they are executed, graphical
moving task didn't change order.
--
Best regardsYou have lines with arrows between the tasks. They define the flow. Remove your current lines (the
one you need to re-arrange) and draw new lines, to your liking.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
<anxcomp@.gmail.com> wrote in message news:1194381069.963177.83560@.50g2000hsm.googlegroups.com...
> Hello,
> I created one maintenance plan with one schedule, it includes several
> tasks. How I can change order on with they are executed, graphical
> moving task didn't change order.
> --
> Best regards
>|||Hello Tibor :)
> You have lines with arrows between the tasks. They define the flow. Remove your current lines (the
> one you need to re-arrange) and draw new lines, to your liking.
Are you sure this working, I tray arrange flow between the tasks use
lines, but logs show me that tasks are executed on different order.
--
Best regards|||Yes, it should work. I can't say why it isn't working for you, except for guesses like your not
editing the correct package... Sorry :-(
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
<anxcomp@.gmail.com> wrote in message news:1194388800.134252.68680@.o38g2000hse.googlegroups.com...
> Hello Tibor :)
>> You have lines with arrows between the tasks. They define the flow. Remove your current lines
>> (the
>> one you need to re-arrange) and draw new lines, to your liking.
> Are you sure this working, I tray arrange flow between the tasks use
> lines, but logs show me that tasks are executed on different order.
> --
> Best regards
>
>|||You are right, it is working. Sorry and thanks, my mistake. I looked
at order on log files. SQL Server wrote on wrong order, but when I
looked at individual start and stop date for each tasks, everything is
on right order.
Thank for your help.
--
Regards,
anxcomp|||Glad you got it working.. :-)
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
<anxcomp@.gmail.com> wrote in message news:1194459342.715819.182790@.d55g2000hsg.googlegroups.com...
> You are right, it is working. Sorry and thanks, my mistake. I looked
> at order on log files. SQL Server wrote on wrong order, but when I
> looked at individual start and stop date for each tasks, everything is
> on right order.
> Thank for your help.
> --
> Regards,
> anxcomp
>