If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Parameter default value
Any ideas how to retrieve a parameter's default value for an Access/Jet
PROCEDURE a.k.a Parameter Query (PARAMETERS declaration)? I created the proc/Query using this SQL: CREATE PROCEDURE Proc5 ( argdata_col VARCHAR(10) = 'Hello' ) AS SELECT key_col, data_col FROM Test WHERE data_col = IIF(argdata_col IS NULL, data_col, argdata_col); It's Jet 4.0 syntax so you need to put Access XP/2003 into ANSI-92 query mode or use ADO e.g. CurrentProject.Connection.Execute _ "CREATE PROCEDURE Proc5 (" & _ "argdata_col VARCHAR(10) = 'Hello' " & _ ") AS " & _ "SELECT key_col, data_col " & _ "FROM Test " & _ "WHERE data_col = " & _ "IIF(argdata_col IS NULL, data_col, argdata_col); " I presumed using the respective ADOX.Procedure object's Command object that it would pre-fill the Parameter object's Value property for me using the default, but no luck (in the VBE Immediate Window): Set oCat = CreateObject("ADOX.Catalog") oCat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Tempo\TestProcs.mdb" Set oComm = oCat.Procedures("Proc5").Command ? oComm.Parameters("argdata_col").Value = vbEmpty True DAO 3.6 doesn't appear to help me either: Set db = DBEngine.OpenDatabase("C:\Tempo\TestProcs.mdb") ? db.QueryDefs("Proc5").Parameters(0).Value = vbEmpty True I hope I'm not faced with parsing the SQL because my next proc/Query looks like this: ? db.QueryDefs("Proc6").SQL PARAMETERS argdata_col1 Text ( 10 ) = ';:,'',:;', argdata_col2 Text ( 10 ) = 'Yes'; SELECT key_col, data_col FROM Test WHERE data_col = IIF(argdata_col1 IS NULL, argdata_col2, argdata_col1); Any ideas? Many thanks. |
#2
|
|||
|
|||
|
#3
|
|||
|
|||
MGFoster wrote: Any ideas how to retrieve a parameter's default value for an Access/Jet PROCEDURE a.k.a Parameter Query (PARAMETERS declaration)? Problems: Your 1st "query" is an incorrect T-SQL stored procedure Sorry, I thought I'd made it clear this is an Access/Jet PROCEDURE. I gave the (I hope) Access-friendly name 'parameter Query'. I posted code to create the proc but perhaps this wasn't explicitly MS Access enough (could potentially apply to an Access ADP MSDE/MSSQL project perhaps, hence your T-SQL assumption?) You've explicitly set the default value, "Hello". Why are you trying to read a known value? The data is meaningless. It's just a test Your final query is neither a stored procedure nor a valid Access query. What do you mean by 'valid Access query' here? This could just be semantics i.e. is what results from a Jet CREATE PROCEDURE statement a 'stored procedure'? Here is some more explicit code to create an .mdb Access/Jet database with a test table and data, create the proc, re-read the definition and, to demonstrate it is a valid Jet PROCEDURE, execute it: Sub Test_Access_Jet() On Error Resume Next Kill "C:\Test.mdb" On Error GoTo 0 Dim cat As Object Set cat = CreateObject("ADOX.Catalog") With cat .Create _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Jet OLEDB:Engine Type=4;" & _ "Data Source=C:\Test.mdb" With .ActiveConnection .Execute _ "CREATE TABLE Test (" & _ " key_col INTEGER NOT NULL," & _ " data_col VARCHAR(10));" .Execute _ "INSERT INTO Test VALUES" & _ " (1, 'Plenty');" .Execute _ "INSERT INTO Test VALUES" & _ " (2, NULL);" .Execute _ "INSERT INTO Test VALUES" & _ " (3, 'N/A');" .Execute _ "CREATE PROCEDURE TestProc " & _ "(arg_data_col VARCHAR(10) = 'N/A') AS " & _ " SELECT Key_col, data_col" & _ " FROM Test" & _ " WHERE data_col = " & _ " IIF(arg_data_col IS NULL," & _ " data_col, arg_data_col);" Dim rs As Object Set rs = .OpenSchema(16) MsgBox rs!PROCEDURE_DEFINITION Set rs = .Execute("EXECUTE TestProc") MsgBox rs.Source & vbCr & vbCr & rs.GetString Set rs = .Execute("EXECUTE TestProc NULL") MsgBox rs.Source & vbCr & vbCr & rs.GetString Set rs = .Execute("EXECUTE TestProc 'Plenty'") MsgBox rs.Source & vbCr & vbCr & rs.GetString End With End With End Sub I've also opened Test.mdb in Access95 (EngineType=4 creates a Jet 3.x version .mdb) and TestProc opens OK, i.e. prompts for the parameter then returns the correct data (but does not apply the default), so I hope that satisfies the test for 'valid Access query'. (BTW for 'Query design mode' it open in GUI mode by default, not SQL, and in converting to SQL it drops the parameter's default value). I hope this helps you to help me get at this parameter default value. Thanks again. |
#4
|
|||
|
|||
MGFoster wrote: I don't know what you're trying to do w/ a default of ';:,'',:;' Again, the data is meaningless. My point is, it would be tricky to parse the SQL to extract the parameter's value because the parameter value, held in single quotes in the definition, could itself contain single quotes (the two quotes represents a one escaped quote), commas (the delimiting character for parameter definitions), semicolons (the delimiting character between PARAMTERS declaration and main SQL definition), equals signs (the delimiting character between the main parameter definition and the parameter default value definition) etc etc. |
#5
|
|||
|
|||
MGFoster wrote: CREATE PROCEDURE Proc5 ( argdata_col VARCHAR(10) = 'Hello' ) AS SELECT key_col, data_col FROM Test WHERE data_col = CASE WHEN argdata_col IS NULL THEN data_col ELSE argdata_col END Now that I think about it, your parameter name is illeagal. Also, COALESCE is elegant he CREATE PROCEDURE Proc5 ( @data_col VARCHAR(10) = 'Hello' ) AS SELECT key_col, data_col FROM Test WHERE data_col = COALESCE(@data_col, data_col) Back in Access/Jet, any ideas about getting that default parameter value? |
#6
|
|||
|
|||
Hi,
iif( myParam Is Null, default_value, myParam ) assuming that if the parameter has a Null value, it is to be considered that the parameter is not supplied, Vanderghast, Access MVP wrote in message oups.com... MGFoster wrote: CREATE PROCEDURE Proc5 ( argdata_col VARCHAR(10) = 'Hello' ) AS SELECT key_col, data_col FROM Test WHERE data_col = CASE WHEN argdata_col IS NULL THEN data_col ELSE argdata_col END Now that I think about it, your parameter name is illeagal. Also, COALESCE is elegant he CREATE PROCEDURE Proc5 ( @data_col VARCHAR(10) = 'Hello' ) AS SELECT key_col, data_col FROM Test WHERE data_col = COALESCE(@data_col, data_col) Back in Access/Jet, any ideas about getting that default parameter value? |
#7
|
|||
|
|||
|
#8
|
|||
|
|||
MGFoster wrote: What I was trying to get at about Access vs. T-SQL queries/stored procedures (SPs). When using an .adp file you are actually using the MS SQL Server (or, the desktop edition MSDE) DB engine. Your post example was showing a T-SQL SP (not an Access query) which was using the VBA function IIf(); this is incorrect in T-SQL. Please take another at my code. This is not T-SQL, not an .adp file, not SQL Server, not MSDE. It really is Jet/Access. Honest. Please try running my VBA code: it creates a Access/Jet database, table, data, PROC/Query and uses it. |
#9
|
|||
|
|||
|
#10
|
|||
|
|||
MGFoster wrote: I suggest you read the documentation. Thank you. Which documentation? The Microsoft Jet SQL Reference for Data Definition Language: http://office.microsoft.com/en-us/as...322191033.aspx doesn't even mention the use of default values. Thanks again. |
|
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Setting and KEEPING the default chart | redbelly | Charts and Charting | 0 | June 30th, 2005 02:35 PM |
When I am changing my default signature in Outlook 2003 | PA.Dutchman | General Discussion | 0 | May 30th, 2005 02:55 AM |
Default font - possible bulletproof fix in Word 2003 | [email protected] | General Discussion | 0 | January 14th, 2005 09:14 PM |
Outlook 2003 replies via WRONG account, uses Default instead | geek4eye | Installation & Setup | 0 | January 10th, 2005 04:13 PM |
Default Printer Problems | Ella | Setting Up & Running Reports | 1 | June 7th, 2004 12:01 AM |