Stored procedure list and parameter number used in conjunction with ComboBox - tsql

I'm trying to get a list of all the user defined stored procedures to populate a combobox with. The idea was to manually create a table with the following columns:
SProc Name, Number of Inputs, Parameter 1, Parameter 2 ...
The user is meant to click a button and a SProc selects all this data from that table, loads it into an array and populates the combo box.
The User is meant to then select a stored proc name from the combobox, and the number of parameters required are shown (with the relevant names).

As per our discussion in SO chat:
SELECT
sprocs.ROUTINE_NAME,
parms.PARAMETER_NAME,
parms.DATA_TYPE
FROM
INFORMATION_SCHEMA.ROUTINES sprocs
LEFT OUTER JOIN INFORMATION_SCHEMA.PARAMETERS parms ON parms.SPECIFIC_NAME = sprocs.ROUTINE_NAME
WHERE
sprocs.ROUTINE_TYPE = 'PROCEDURE'
--AND PATINDEX('/*<SomeKeyToSearch>*/', sprocs.ROUTINE_DEFINITION) > 0
This will give you the list of all sprocs with their parameters and data types. Just be warned that you also need to pay close attention to data types (precision, scale, max length, etc), since this will be used to allow a user to call an arbitrary stored procedure. Once you get this entire table in your C# application, you can group/sort/limit based on whatever criteria you want. If you want to ensure only specific sprocs get returned from the above query, just add a top-level comment to the sproc with some sort of key that you can search on.
Good luck.

Related

Access how to show record count of a table on a form

I want to show a variable value (record count of a table) on an Access form. I tried with a textbox by defining its control source with the following and many other internal functions but all returned only errors. Anyone can help? Thanks
select count(*) from TableName
I would also suggest the DCount domain aggregate function as suggested by Andre, but to offer an alternative, if TableName is the Record Source for your form, you can also use:
=Count(*)
To count all records in the Record Source, or:
=Count([FieldName])
To count all non-null values of a particular field in the Record Source.
You need = and domain functions.
=DCount("*", "TableName")
should work as control source.

How to store DLookup from [Form] to Table Field in MsAccess 2013?

I have two MS Access tables: IdMhs and T_UKT. I want to automatically fill in [IdMhs].[SPP] from some criteria in [T_UKT].[UKT]. I cannot put it in query relationship, because the row cannot be edited on a form.
So I make a form and I get the number SPP (a textbox on form) automatically by using and it works fine:
=DLookUp("SPP";"T_UKT";"UKT = " & [Form].[UKT])
The problem is: the lookup value just shows on the form, and the results are not filled in the field in table ([IdMhs].[SPP]).
Any idea what an expression I should write to fill it in IdMhs table automatically?
Need macro or VBA code to save value into table. If form is bound to IdMhs table, simply like:
Me!SPP = Me.tbxSPP
The real trick is figuring out what event to put the code into. You have a control (possibly combobox) where the UKT value is selected? Use its AfterUpdate event.
Why do you need to save the SPP value and not just retrieve it in a query that joins tables?
What is nature of table relationship? Is T_UKT a lookup table? If so should be able to include it in form RecordSource and then the SPP value would be available for display in textbox and DLookup not needed. Domain aggregate functions can perform slowly on forms and reports and should be a last resort option. The same code would be used to save the value. The query join should be 'show all records from IdMhs and only those from T_UKT that match'. Set textbox bound to T_UKT SPP field as Locked Yes, TabStop No.

I would like to use a parameter for the table name. The table names can be presented to the user from a database view.

I would like to use a parameter for the table name. I have an application that creates several new tables each month. I therefore need the table name to be sent into CR via a parameter. The fields for the tabkes are always identical. I can present a list (view) from the database to the end user that would display a user friendly name for the table, when the user selects the instance they want I then have the table name I want to report from.
I'm not sure if that is possible. Even if your tables have the same structure, the field names will ultimately be different. Let's say you have a {table1.field1} in your report. Now you want to run the report from table2 instead of table1. So your field now would have to become {table2.field1}. Does that make sense? I think a better approach might be to try stored procedures that will create the fields you need so the field names won't change.

Entity Framework - stored procedure

My stored procedure looks like this:
create Procedure procLoc
AS
BEGIN
select
pr.name, loc.address
from
Profile pr
join
Location loc on pr.id = loc.id
END
For the add function Import dialog box that comes up, there are the following options
None
Scalars
Complex
Entities
Which option would I select in this scenario?
Since your stored procedure is returning multiple values: pr.name,loc.address, you'll only have 2 choices- Complex or Entities. If you already have an entity mapped with Name/Address properties you can choose it, otherwise choose complex. I usually click the Get Column Information button and then Create New Complex type and let it generate one for me.

Create a new FileMaker layout showing unique records based on one field and a count for each

I have a table like this:
Application,Program,UsedObject
It can have data like this:
A,P1,ZZ
A,P1,BB
A,P2,CC
B,F1,KK
I'd like to create a layout to show:
Application,# of Programs
A,2
B,1
The point is to count the distinct programs.
For the life of me I can't make this work in FileMaker. I've created a summary field to count programs resetting after each group, but because it doesn't eliminate the duplicate programs I get:
A,3
B,1
Any help much appreciated.
Create a a summary field as:
cntApplicaiton = Count of Application
Do this by going into define fields, create a field called cntApplication, type summary. In the options dialogue make the summary field a count on application
Now create a new layout with a subsummary part and nobody. The subsummary should be sorted on Application. Put the Application and cntApplication fields in subsummary. If you enter browse mode and sort by Application you ought to get the data you want.
You can also create a calc field with the formula
GetSummary(cntApplication; Application)
This will allow you to use the total number of Applications with in a record
Since I also generate the data in this form, the solution I've adopted is to fill two tables in FileMaker. One provides the summary view, the other the detailed view.
I think that your problem is down to dupliate records and an inadequate key.
Create a text field called "App_Prog". In the options box set it to an auto-enter calc, unchecking the 'Do not replace...' option, and use the following calc:
Application & "_" & Program
Now create a self join to the table using App_Prog as the field on both sides, and call this 'MatchingApps'.
Now, create (if you don't alread have one) a unique serial number field, 'Counter' say, and make sure that you enter a value in each record. (Find all, click in the field, and use serial number option in'Replace Field Contents...')
Now add a new calc field - Is_Duplicate with the following calc...
If (Counter = MatchingApps::Counter; "Master Record" ; "Duplicate")
Finally, find all, click in the 'Application field, and use 'Replace Field Contents...' with a calculation to force the auto-enter calc for 'App_Prog' to come up with a value.
Where does this get you? You should now have a set of records that are marker either "Master Record" or "Duplicate". Do a find on "Master Record", and then you can perform your summary (by Application) to do a count of distinct application-program pairs.
If you have access to custom functions (you need FileMaker Pro Advanced), I'd do it like this:
Add the RemoveDuplicates function as found here (this is a recursive function that takes a list of strings and returns a list of unique values).
In the relationships graph, add another occurrence of your table and add an Application = Application relationship.
Create a calculated field in the table with the calculation looking something like this:
ValueCount(RemoveDuplicates(List(TABLE2::Program)))
You'll find that each record will contain the number of distinct programs for the given application. Showing a summary for each application should be relatively trivial from here.
I think the best way to do this is to create a separate applications table. So as you've given the data, it would have two records, one for A and one for B.
So, with the addition of an Applications table and your existing table, which I'll call Objects, create a relationship from Applications to Objects (with a table occurrence called ObjectsParent) based on the ApplicationName as the match field. Create a self join relationship between Objects and itself with both Application and Program as the match fields. I'll call one of the "table occurrences" ObjectsParent and the other ObjectsChildren. Make sure that there's a primary key field in Objects that is set to auto-enter a serial number or some other method to ensure uniqueness. I'll call this ID.
So your relationship graph has three table occurrences:
Applications::Applicaiton = ObjectsParent::Application
ObjectsParent::Application = ObjectsChildren::Application, ObjectsParent::Program = ObjectsChildren::Program
Now create a calculation field in Objects, and calculating from the context of ObjectsParent, give it the following formula:
AppCount = Count( ObjectsChildren::ID )
Create a calculation field in Applications and calculating from the context of the table occurrence you used to relate it to ObjectsParent with the following formula:
AppCount = ObjectsParent::AppCount
The count field in Objects will have the same value for every object with the same application, so it doesn't matter which one you get this data from.
If you now view the data in Applications in list view, you can place the Applications::Application and Applications::AppCount fields on the layout and you should get what you've requested.