Page 1 of 2 12 LastLast
Results 1 to 40 of 67

Thread: open more than one table

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780

    open more than one table

    i have front end app that i need to access records from 2 different tables. and then i need to be able to hceck and see if the recrds are different at all. i have a sub that i already made but it doesn't work the way that i want it. any help is greatly appriciated.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    Show the code that you have, what is does and more important what is DOESN'T. Do you want to compare records? If so what are the table like?
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    this is my code. there are two tables that have info about the same tools. i need to check both of them to see if they have info on the same tool number. if they do then the info neeeds to be displayed on the screen. my problem is editing these records. i need to be able to edit all the info from both tables. this is my code to check if it has changed
    VB Code:
    1. Private Sub checker()
    2. If txtDrNum.Text <> rs![Drawing Number] Then
    3.     changes = True
    4.     MsgBox "Drawing number is different"
    5. ElseIf cmbTType.Text <> rs![Type of tool] & "" Then
    6.     changes = True
    7.     MsgBox "Tool Type is different"
    8. ElseIf txtDie.Text <> rs![Die Type] & "" Then
    9.     changes = True
    10.     MsgBox "Die Type is different"
    11. ElseIf txtDate.Text <> rs![Date Created] & "" Then
    12.     changes = True
    13.     MsgBox "Date is different"
    14. ElseIf cmbVend.Text <> rs!Vendor & "" Then
    15.     changes = True
    16.     MsgBox "Vendor is different"
    17. ElseIf cmbDepart.Text <> rs!Department & "" Then
    18.     changes = True
    19.     MsgBox "Department is different"
    20. ElseIf txtAssign.Text <> rs![Tool Number Assigned by] & "" Then
    21.     changes = True
    22.     MsgBox "Someone Else assigned the number"
    23. ElseIf txtSketch.Text <> rs!PSketch & "" Then
    24.     changes = True
    25.     MsgBox "The sketch is different"
    26. ElseIf txtStore.Text <> rs![Storage Location] & "" Then
    27.     changes = True
    28.     MsgBox "Storage location is different"
    29. ElseIf txtPMType.Text <> rs!PMType & "" Then
    30.     changes = True
    31.     MsgBox "Different PMType"
    32. Else
    33.     changes = False
    34. End If
    35. Dim sql As String
    36. sql = "SELECT * FROM Status WHERE [Tool number] = '" & ToolID & "'"
    37.  
    38. If SDrs.State = adStateClosed Then
    39.     SDrs.Open sql, DBConn, adOpenDynamic, adLockOptimistic
    40. Else
    41.     GoTo KeepGoing
    42. End If
    43. KeepGoing:
    44.     If cmbStatus.Text <> SDrs!status & "" Then
    45.         changes = True
    46.     ElseIf txtDesc.Text <> SDrs!Description & "" Then
    47.         changes = True
    48.     Else
    49.         changes = False
    50.     End If
    51. End Sub
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  4. #4
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    Can you just join the two tables on the Tool Number? That will give you only tools that have information in both tables, provided it's an Inner Join.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    i wanted to do that @ first but i can't becausethere are tools that need to show up that don't have a status assigned to them. the two tables are: Tool Data & Status, i only need 2 fields from status. everything works fine until a tool number is found that is not in status. then the app thinks that it had reached eof and doesn't display any thing else in those 2 boxes after that. there are tools that still have a status assigned to them but they don't show up because the rs for the status table has ended.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  6. #6
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    You could do a Left Join on [Tool Data] to [Status]. That would give you everything in [Tool Data] and return NULL values for the [Status] columns in the Select statement.
    Code:
    Select td.Col1
         , td.Col2
         , st.Status
         , st.Description
    From [Tool Data] td Left Join [Status] st On td.[Tool Number] = st.[Tool Number]
    You code would remain the same, except that you would use rs in place of SDrs.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    so how would i update the status table if i change the status of a tool?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  8. #8
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    What all is in the status table and why would you not include the status as a column in [Tool Data]?

    You could always check if the "Status" field in the recordset is null and if so, issue an Insert statement to insert it into the Status table.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    i didn't make the tables up or else the status column would be in there.
    there are 4 fields in the status table
    tool number
    description
    status
    date
    the only ones that i need are description and status, tool number is already there. how would i go about an insert statement?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  10. #10
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    You will need to requery your recordset after performing this update to pick up the new values:
    VB Code:
    1. Dim sSql As String
    2.  
    3. sSql = "Insert Into [Status] ([status], [description], [tool number], [date]) " & _
    4.        "Values ('" & cmdStatus.Text & "', '" & txtDesc.Text & "', '" & ToolID & "', '" & Date & "')"
    5.  
    6. 'Assuming conn is your Connection Object
    7. conn.Execute sSql
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    so what you're suggesting is this
    use a left join to get all of the records that i want
    then when i need to update from editing use the following
    VB Code:
    1. Dim sSql As String
    2.  
    3. sSql = "Insert Into [Status] ([status], [description], [tool number], [date]) " & _
    4.        "Values ('" & cmdStatus.Text & "', '" & txtDesc.Text & "', '" & ToolID & "', '" & Date & "')"
    5.  
    6. DBConn.Execute sSql
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  12. #12
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    What I suggest you do is redesign your database!

    According to what I understand you are trying to do, yes. If you do a left join and the tool does not exist in the Status Table, then NULL will be returned for the Status & Description Columns. During your check to see if anything has changed, if rs!status is null and cmdStatus.Text <> "" then you would want to run the insert statement (assuming that if a tool is in the Status table, it's status can't be NULL).

    If the status field is not null, meaning the tool exists in the Status table, I think you will be okay with doing a rs.Update to update the recordset.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    redesigning the DB sounds like a wonderful idea to me as well but i am only the low man on the totem pole, and i don't have enough expeirence with SQL to do that. i will try the suggestions you told me tomorrow morning as i won't have enough time to impliment today. thanx for your help so far, i'll let you know how it turns out. g'day
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    ok i have another question. say for instance that i am going to add a new tool, that would require me to put up a new entry in the Tool table as well as the status table. how am i going to be able to add some thing to both of the tables?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  15. #15
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    That depends on how your tool number is generated. Are the user's entering the Tool Number or is your database generating the Tool Number?

    If your users are assigning the number, then I'd run two seperate Insert Statements. One to insert data into the [Tool Data] table and the other to insert into the [Status] table.

    What type of database are you using? (Access, SQL Server, mySQL, etc.)
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    i think that we are using SQL server here(not entirely sure) but i do know that in order to generate a new tool number we have a table with one number in it. when the user adds a new tool the app opens that table and then grabs that number adds the appropraite letters and then adds one to the number that was in the table. and closes the table.
    EX.
    NEWNUM Table
    100

    The user clicks the add a tool button
    the letters are added
    OLMOV100
    the app writes that number back to the table adding one.

    NEWNUM Table
    101
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  17. #17
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    If you are using SQL Server, I'd create one Stored Procedure to handle this for you:
    Code:
    Create Procedure ins_Tool @ToolID varchar(50)
                            , @ToolDataField2 varchar(50)
                            , ...
                            , @Status varchar(50)
                            , @Description varchar(100)
                            , @StatusDate smalldatetime
    As
    
    Insert Into [Tool Data] (ToolID, ToolDataField2, ...)
    Values (@ToolID, @ToolDataField2, ...)
    
    Insert Into [Status] (ToolID, [Status], [Description], [Date])
    Values (@ToolID, @Status, @Description, @StatusDate)
    Then in your app, instead of running two seperate insert statments, just run the stored procedure:
    VB Code:
    1. Dim sSql As String
    2.  
    3. sSql = "ins_Tool @ToolID='" & txtToolID.Text & "', "
    4. sSql = sSql & "@ToolDateField2='" & txtSomeField.Text & "', "
    5. 'Fill in other fields/parameters here
    6. sSql = sSql & "...=...,"
    7. sSql = sSql & "@Status='" & cmdStatus.Text & "', "
    8. sSql = sSql & "@Description='" & txtDescription.Text & "', "
    9. sSql = sSql & "@StatusDate='" & Date & "'"
    10.  
    11. conn.Execute sSql
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    um..............i've never done a stored procedure, i have heard of them but i donno how in the world to even start to do one.

    i put in the left join Select statement and i got a syntax error @ the word left.
    VB Code:
    1. OpenSQL = "SELECT [Tool Data].ToolNumber, [Tool Data].[Drawing Number],[Tool Data].[Type of Tool], [Tool data].[Die Type]," & _
    2.               "[Tool Data].[Date Created], [Tool Data].Vendor, [Tool Data].Department, [Tool Data].[Tool Number assigned by]," & _
    3.               "[Tool Data].PSketch, [Tool Data].[Storage Location],[Tool Data].PMType,Status.Description,Status.Status, Status.Date" & _
    4.               "FROM [Tool Data] LEFT JOIN [Status] ON [Tool Data].ToolNumber = Status.[Tool number]"
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  19. #19
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    You need a space before the FROM clause:
    VB Code:
    1. OpenSQL = "SELECT [Tool Data].ToolNumber, [Tool Data].[Drawing Number],[Tool Data].[Type of Tool], [Tool data].[Die Type]," & _
    2.               "[Tool Data].[Date Created], [Tool Data].Vendor, [Tool Data].Department, [Tool Data].[Tool Number assigned by]," & _
    3.               "[Tool Data].PSketch, [Tool Data].[Storage Location],[Tool Data].PMType,Status.Description,Status.Status, Status.Date" & _
    4.               " [b]FROM[/b] [Tool Data] LEFT JOIN [Status] ON [Tool Data].ToolNumber = Status.[Tool number]"
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  20. #20

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    ok that works, ther space made the form load. the problem is this though. this is my display code.
    VB Code:
    1. txtNum.Text = rs!ToolNumber
    2.             txtDrNum.Text = rs![Drawing Number] & ""
    3.             cmbTType.Text = rs![Type of tool] & ""
    4.             txtDie.Text = rs![Die Type] & ""
    5.             txtDate.Text = rs![Date Created] & ""
    6.             cmbVend.Text = rs!Vendor & ""
    7.             cmbDepart.Text = rs!Department & ""
    8.             txtAssign.Text = rs![Tool Number Assigned by] & ""
    9.             txtSketch.Text = rs!PSketch & ""
    10.             txtStore.Text = rs![Storage Location] & ""
    11.             txtPMType.Text = rs!PMType & ""
    the values from the Tools table are input into the boxes, the values from the status table are not being input to the boxes. it works the first time but doesn't work after that. i tried putting this in there
    cmbStatus.text=rs!Status.
    but it doesn't work.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    never mind about the last post i got it to work it was some thing stupid. i forgot to put it in the other parts of the display function.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    so now i have it all working fine except for saving the changes and saving a new tool. i would do two insert statements correct?
    one for the Tools table and one for the Status table?


    sSql= INSERT INTO [Tools Data]([Tool number].......)
    VALUES('"&txtTNum.text &'",...............)

    dbconn.execute sSql

    this would be the same for the status table as well, and it would obviously only be done if the user wanted to save some thing(Changes or New tool)
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  23. #23
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    If the user is adding a new row to the [Tool Data] table, ie) Adding a new tool, then you would use the INSERT statements. If the user is updating an existing TOOL, then you would need to issue an Update statement:
    VB Code:
    1. Dim sSql  As String
    2.  
    3. sSql = "Update [Tool Data] "
    4. sSql = sSql & "Set Field1 = '" & txtField1.Text & "', "
    5. sSql = sSql & "    Field2 = '" & txtField2.Text & "' "
    6. sSql = sSql & "Where ToolID = '" & ToolID & "'"
    7.  
    8. Conn.Execute sSql

    You should really look into using stored procedures. They are the recommended way to handle queries rather than inline SQL statements such as the one's we've been passing around in this thread.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  24. #24

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    ok thanx, do you know where there is a place that i can read up on stored procedures? i'm kinda scared to try one as i don't want to mess the DB up. but i'm willing to give it a try.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    VB Code:
    1. StatSql = "INSERT INTO [Status] ([status], [description], [tool number], [date]) " & _
    2.        "Values ('" & cmbStatus.Text & "', '" & txtDesc.Text & "', '" & ToolID & "', '" & Date & "')"
    3.  
    4. ToSQL = "INSERT INTO [Tool Data]([Tool Number],[Drawing Number],[Type of Tool], [Die Type], " & _
    5.         "[Date Created],[Vendor], [Department], [Tool Number assigned by],[PSketch],[Storage Location], [PMType]) " & _
    6.         VALUES('" & txtNum.Text & "', '" & txtDrNum.Text & "', '" & cmbTType.Text & "', '" & txtDie.Text & "', '" & _
    7.                & txtDate.Text & "', '" & cmbVendor.Text & "', '" & cmbDepart.Text& "', '" & txtAssign.Text & "', '" & _
    8.                & txtSketch.Text & "', '" & txtStore.Text & "', '" & txtPMType.Text & "')"
    those are my insert statements but the bottom one is in red do you know why?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  26. #26
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    looks like you're missing a quote before, and a space after VALUES:

    StatSql = "INSERT INTO [Status] ([status], [description], [tool number], [date]) " & _
    "Values ('" & cmbStatus.Text & "', '" & txtDesc.Text & "', '" & ToolID & "', '" & Date & "')"

    ToSQL = "INSERT INTO [Tool Data]([Tool Number],[Drawing Number],[Type of Tool], [Die Type], " & _
    "[Date Created],[Vendor], [Department], [Tool Number assigned by],[PSketch],[Storage Location], [PMType]) " & _
    " VALUES('" & txtNum.Text & "', '" & txtDrNum.Text & "', '" & cmbTType.Text & "', '" & txtDie.Text & "', '" & _
    & txtDate.Text & "', '" & cmbVendor.Text & "', '" & cmbDepart.Text& "', '" & txtAssign.Text & "', '" & _
    & txtSketch.Text & "', '" & txtStore.Text & "', '" & txtPMType.Text & "')"

  27. #27

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    yeah i found that, thanks for the help tho. to everyone, vb_dba you are the man
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  28. #28
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    Originally posted by Dubya007
    ok thanx, do you know where there is a place that i can read up on stored procedures? i'm kinda scared to try one as i don't want to mess the DB up. but i'm willing to give it a try.
    You should have no fear about creating a simple stored procedure that does a SELECT statement, for example.

    We create all of our SPROCS in QUERY ANALYZER with a .SQL script file. Some people might choose to just load them into the DB and then edit them in the DB, but since we have so many customers, we need to distribute changes to SPROCS, so having them in .SQL files kind of treats them like SOURCE vs COMPILED.

    At any rate - here is a simple .SQL script that we execute in QA. It's stored in a text file called GETAPPELE_P.SQL - created in QA and saved/edited/re-saved from QA.

    The first thing we do is a USE statement - making sure we are "in the right DB" - we have lots and lots of DB's. The two SET statements are just boilerplate we've been using forever - don't even remember why...

    The "if exists" statement will DROP the SPROC if it's already in the DB.

    Then we have a very simple SELECT statement - all this SPROC does is return a RS. It's as if the SELECT was in-line in VB code - no danger to the DB with this. The SELECT is wrapped in a "CREATE PROCEDURE" statement and "ended" by a GO. The SET NOCOUNT ON is a standard statement we use in SPROCS to keep ADO from getting those little "1 row(s) affected" message in the RS - these can sometimes get in the way.

    At the end we GRANT EXEC permission to this SPROC to the "SQL role" that needs it - and then finish up with some standard "SET" statements.

    Whenever we go into QA and change this SPROC, we save it (so the .SQL text file is kept up to date) and then press the "EXECUTE QUERY" button on the top toolbar. Basically dropping and re-creating the SPROC in the DB.

    SPROCS are great - you do not have to give users access to tables, only SPROCS - so they are a secure way to offer your data to the user group. They are pre-compiled - so they run faster.

    Plus they can be very complex - we actually adjudicate medical claims in a SPROC - it's 2472 lines long!!

    Code:
    Use Stufiles
    SET QUOTED_IDENTIFIER ON 
    GO
    SET ANSI_NULLS ON 
    GO
    
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetAppEle_P]') 
    	and OBJECTPROPERTY(id, N'IsProcedure') = 1)
    drop procedure [dbo].[GetAppEle_P]
    GO
    
    Create Procedure GetAppEle_P
    as
      Set NoCount On
      Select AER.AppID, AER.ROleID
      FROM AppElemRole_T AER
      WHERE AER.AppId < 10000 and AER.RoleId<1000
      ORDER BY AER.AppId DESC
    GO
    GRANT EXEC ON GetAppEle_P to StufilesUser
    GO
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO

  29. #29

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    first i'd like to thank you for your response szlamany. second: i'm sure you already told me this but, maybe i didn't understand it. lets say that i am going to make an sproc. do i start in SQL or in VB. and then lets say that i have made on called Retrieve that grabs all of my data. in VB how do i access it?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  30. #30
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    First question - then I'll answer the rest...

    This is MS SQL Server we are talking about - right? Also, you do use QUERY ANALYZER - right?

  31. #31

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    i use sql server. i don't use query analyzer, i donno what it is.
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  32. #32
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    Do you use ENTERPRISE MANAGER?

  33. #33

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    yes
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  34. #34
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    Ok, in ENTERPRISE MANAGER (EM) - open up the CONSOLE ROOT on the left side and open up all the way till you get to your DB open.

    Click on TABLES - you will see all your tables in the panel on the right.

    From the TOOLS menu up top, select SQL QUERY ANALYZER.

    This launches QUERY ANAYLZER (QA) - giving you a simple query window.

    Type something like "SELECT GETDATE()" in that window and click the EXECUTE QUERY button up top.

    It will execute that simple query and show a RECORDSET in the panel below.

    The button on the left - NEW QUERY - will create a new empty query window. In that window, I would type all the stuff I posted in the last post about CREATE PROCEDURE.

    Once done typing all that, I would click SAVE QUERY button and give the file a name. It will get saved with a file extension of .SQL, but it is simply a NOTEPAD-LIKE text file.

    Once saved, I would then click the EXECUTE QUERY button and it would load that SPROC into the DB.

  35. #35

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    just copy & paste all that code in there?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  36. #36
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    Sure - why not?

    Just hand edit every ocurrence of GETAPPELE_P to be the name you want for your SPROC. Also change the SELECT statement in the CREATE PROCEDURE to be the SELECT you are looking to do.

    The USE STUFILES - should be USE {name of your db}

    And if you don't do security through roles, get rid of the GRANT EXEC statement at the bottom.

    Once you EXECUTE QUERY and the SPROCS is in your database, open a NEW QUERY window and put in that window just

    Code:
    EXEC {procedure name}
    That will test run your SPROC...

  37. #37

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    GetAppEle_P this is the name of the sproc?
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  38. #38
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    That is the name of the SPROC.

    Feel free to ask questions about any part of what I posted...

  39. #39

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2003
    Location
    Portville NY
    Posts
    780
    Use Stufiles
    what is that then? i thought that was the name of the sproc
    "...Men will still say THIS was our finest hour"
    If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?

  40. #40
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    USE is a command that "directs" QA to USE a particular DATABASE.

    Even though you got to QA from the TOOL menu in EM - with your database open - you still have a DROP DOWN at the top of QA that would allow you to change to a different DATABASE - MASTER for instance.

    And putting your SPROC in the MASTER DB would be a bad thing.

    So USE {databasename} is just a safety net - making sure that the commands that follow will be executed against the proper DATABASE.

    You can also get into QA through START>PROGRAMS - if you do it that way, the DATABASE selected in that dropdown box at the top will not always be what you want - but will be what the "admin" people have set your default DATABASE to be.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width