Showing posts with label point. Show all posts
Showing posts with label point. Show all posts

Tuesday, March 27, 2012

automatically update another field based on other parts of the record

Sql is not a strong point with me so I'm just going to throw this out there. I have a stored procedure that updates the quantity in my 'CartItems' table. Is there a way to have something else happen within the stored procedure that will update another field based on other parts of the record? There is a 'lineTotal' field that I need to equal the 'pounds * itemSell' fields which are both fields within this record.

CREATE PROCEDURE UpdateCartItem
(
@.cartItemID Int,
@.newQuantity numeric(9)
)
AS
UPDATE CartItems Set quantity = @.newQuantity
WHERE cartItemID = @.cartItemID
GO

sure. you can update as many fields as you want within the UPDATE statement.

CREATE PROCEDURE UpdateCartItem
(
@.cartItemID Int,
@.newQuantity numeric(9)
)
AS

SET NOCOUNT ON

UPDATE
CartItems
Set
quantity = @.newQuantity
,lineTotal =pounds * itemSell
WHERE
cartItemID = @.cartItemID

SET NOCOUNT OFF

GO

|||Or make the lineTotal a computed column. Just modify the table and tell it the lineTotal column is equal to pounds*itemSell.sql

Sunday, March 25, 2012

Automatically run a stored procedure at 6am every day?

Hi All,

I'm wondering if anyone can point me at some online resources that
demonstrate how to run a stored procedure against an SQL Server 2000
server at 6am each day?
Any help much appreciated!

Much warmth,

planetthoughtfulhttp://msdn.microsoft.com/library/e...tomate_4v1v.asp

--
David Portas
SQL Server MVP
--|||http://msdn.microsoft.com/library/d...p_adda_9tbk.asp

Monday, March 19, 2012

Automatic FileGrowth

At what point does SQL actually begin the file growth?
Is it when the database reaches a secific percentage of
the file size or when the database reaches a specific
size. For example, if I have a 100GB database (90 GB
used, 10GB free) and it is set to grow 10%, does the
database grow 10% when the database reaches 91GB or when
it reaches 100GB?It doesn't grow until it is 100% full and more space is needed due to some
SQL statement is executed (an INSERT, for instance).
--
Tibor Karaszi, SQL Server MVP
Archive at:
http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Philip Wilhelm" <philip.wilhelm@.astongroup-us.com> wrote in message
news:05ca01c3a92e$c81d2990$a501280a@.phx.gbl...
> At what point does SQL actually begin the file growth?
> Is it when the database reaches a secific percentage of
> the file size or when the database reaches a specific
> size. For example, if I have a 100GB database (90 GB
> used, 10GB free) and it is set to grow 10%, does the
> database grow 10% when the database reaches 91GB or when
> it reaches 100GB?|||Philip
http://www.sql-server-performance.com/database_settings.asp
"Philip Wilhelm" <philip.wilhelm@.astongroup-us.com> wrote in message
news:05ca01c3a92e$c81d2990$a501280a@.phx.gbl...
> At what point does SQL actually begin the file growth?
> Is it when the database reaches a secific percentage of
> the file size or when the database reaches a specific
> size. For example, if I have a 100GB database (90 GB
> used, 10GB free) and it is set to grow 10%, does the
> database grow 10% when the database reaches 91GB or when
> it reaches 100GB?

Sunday, March 11, 2012

automatic data import

I just got sql 2005. Can someone point me in the right direction on getting started importing data. I need to be able to load ascii data into SQL 2005 on a weekly basis. This ascii file will have the same data structure but data will change weekly.

I have heard to do this automatically (basically with a click of a button) you should use a DTS package. I also see this SSIS. I am trying to understand what to use for this import process. I would really appreciate any help on this. Thanks.

Start with the Import Wizard (in SQL Server Management Studio).

-Jamie

Thursday, March 8, 2012

Automated import of XLS to SQL

I have a customer who insists on emailing an excel spreadsheet to me to be uploaded to a sql database. I came across a script at one point that laid out how I would script this out. Basically it was in parts, 1. open email program and get attachment. 2.After saving attachment closing email program in order to be used the next day or next time an attachment was sent. 3. import the attached spreadsheet into SQL database. I would also like to be able to schedule this to run with the built in Windows 2000 scheduler.

Can anyone help me out on this one??

Thanks,
WillWhat email application are you using ... Also, you want to do all these steps within sql as a job ?|||Currently I have it set up with the pre-security patched version of Outlook 2k. I would love to have it set up as one job that launches each morning at 8am. Currently I have a script that I run manually that opens Outlook, saves the attachment, moves the message to a subfolder, sends a confirmation email then closes Outlook. It is a wsf file (see below) but when I try to run it as a scheduled task it doesn't do a darn thing.

Code:
<job>
<script language="VBScript">
dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objOL = WScript.CreateObject ("Outlook.Application")
Set MAPI = objOL.GetNamespace("MAPI")
Set myStore = MAPI.Folders("Mailbox - Tunisia Information")
Set Folder = myStore.Folders("Inbox")
' Open up the Processed Folder under the inbox
Set DestFldr = Folder.Folders("Processed")
For Each myItem In Folder.Items
For Each att In myItem.Attachments
att.SaveAsFile "\\naslc03\data\TunisiaProdData\" & att.Filename
Next
' Move the Mail to DestFldr
myItem.Move DestFldr
Next

' Create mail message.
Set olMailMessage = objOl.CreateItem(olMailItem)
With olMailMessage
Set olRecipient = .Recipients.Add("TunisiaProdData@.pioneernrc.com")
.Subject = "Tunisia Attachment"
.Body = "The Tunisia email message was created was processed" _
& " and the attachment was successfully saved to the S: Drive."
.Send
End With
Set olMailMessage = Nothing

objOL.quit

</script>
</job>|||Good - You can try to implement this within dts, using the activex script task. Once this task is complete, you can import the excel file. The easiest way to set this up if you have not worked with dts before, is to go to Enterprise Manager -> Databases -> The database you want to import into -> tables. Right click on tables -> All tasks -> Import Data. Follow the instructions - making sure at the end to save it. When you have saved it, you can modify the package under Data Transformation Services -> Local Packages. Open your package in design mode and create an activex script task. Insert your code into that task and run that step to see if it will function properly.|||Thanks I will give that a shot and let you know.|||If adding it as an activex script does not work, you can still keep the rest of the package (the excel import). When you create a job based on this package, you can add a step that will execute an operating system command (which would be your script).