Passing Table and Column as method parameters - database

I am working on a VB.Net app that is connecting to a database with LINQ. Right now I am creating search fields for different parts of the database which have autocomplete text boxes, where I want the AutoCompleteSource to be specific fields in a table.
For example, the text box for the Part Number search would have all of the data from the Part_Number field in my Parts database.
I am wondering if there is a way to implement a method where I can write a simple query like: From t in tbl Select field where both tbl and field are parameters for the method for the Table and Field respectively.
I've tried programming a query like my small example above, and while the From t In tbl part does not initially present me with errors, Select field gives me the error:
Range variable 'field'hides a variable in an enclosing block or a range variable previously defined in the query expression.

Related

Schema to store/generate dynamic messages with placeholder

I am creating an application to display the notification like facebook. I have database schema to save the user-specific notification. The notification message contains the placeholders. E.g. Suppose we have below notification messages (Calling it Notification Template):
{FrinedName} like your photo.
{FriendName} like your page {PageName}.
{FrinedName} posted a message in {groupName}.
It's {friendName} birthday today.
{FriendName} and {#count} likes your photo
So here the text inside {} represents placeholder and the value of these placeholders need to be replaced at the runtime.
Now I want to keep these placeholders and their value source in database tables.
The Value of different placeholders may refer to the different columns in different tables. (E.g. the value of {FriendName} may belong to the User tables LoginName column, value of {PageName} will refer to Pages table's Name column and the value of {groupname} placeholder refer to the the Groups tables Name column).
So, I would like to get the data dynamically for the placeholders. What is the best way to store such type of data in the database (something like below).
dbo.NotificationTemplates - Table to store all the notification templates
dbo.TemplatePlaceholders - Table to store the placeholders in the template
dbo.TemplatePlaceholdersMapping - Table to store the mapping of placeholders in a template.
dbo.PlaceholderValueProvider - table to store the placeholder's value source, i.e. from where to get the value for placeholder.
My suggestion is to use scalar function, you can have multiple conditions in scalar function and at the end, return your result in one column

Using extended properties (attributes) to columns in an SQL table for defining how data should be input later on

I have never used SQL. I would like to create a table with different columns. Then I would like to create a program which allows the user to insert entries. For each token of the entry, I would like to retrieve from an attribute of the corresponding column the way this particular part of the data entry should be entered. For example, I will have some data retrieved automatically (e.g. the date and time), some for which I will propose the user to insert the last added value, and some for which I will ask the user to explicitly type the value.
I do not know if "Attribute" is the right term; the attributes that I have available for each column at the moment are "Name", "DataType" and "Description"
I want that my program dynamically adapts to the table columns and to the property of each column, especially because I will have several tables to be filled. So my program would check the table columns with their properties, and interact with the user for the creation of a new entry.
Is there a possibility to add attributes to a column?
Otherwise I will have to encode the information I need for my program in the "Description" field (aka "MS_Description").
I googled terms like "sql add column attribute", but I could only find results concerning how to add a column to a table.

OBIEE Characteristic Table with dynamic header

I have original data as shown above with a single record. I have name of the field in one column and value in another column. I need to transform make the heading dynamic as shown below.
I tried with table pivot table and trellis, not no success.
You should be able to do this in a pivot table in OBIEE.
Please see my below screenshot. I was able to get my column originally named 'Total Contracted Cases' to now be called 'USD' because that is the value in the column 'Currency Code'. So for you, you should be able to get the column 'PARAM_VAL1' to be called 'COUNTRY' because that is the value in the column 'PARAM_CD1'. See below for my example:
In the second image, be sure to click on the 'Measure Lables' properties to hide the value.
For columns that are not metrics (no aggregation rule set) that will be used in the 'Measures' section of the pivot table, you will have to define an aggregation rule in the column properties dialog box to keep the value from being converted to null. If your data is as you say it is (a single record), then this should not be an issue; you should be able to pick any aggregation rule and not have to worry about dropping data.

SSRS parameters, populating the available fields list

When producing a list of available parameter properties, rather than manually typing each persons name in one by one, is there any way of just populating the data from the table/view which holds all the possible names?
I assume its in the circled box however all that does it let me point to a dataset and then field which I have tried selecting StaffName (being the field that is the one I'm using) if I then run the report it falls over.
Add a new dataset to the report, maybe called StaffMembersDS. The SQL for it might look like:
SELECT Id, Name
FROM StaffMember;
Then assign Name to Label and Id to Value.
BTW if this is related to your last question you're going to run into the trouble that when a user picks a staff member name from the drop down list they are picking only one value. So for your case you might want the Value field to be tied to Name as well as the label. That would allow you to use the query in your last question - SSRS Parameters - which collects related Id values.
SSRS's concept of a query is largely tied to a data set that you define in Report Data.
When you choose 'Use a query', you should be choosing a pre-defined query from Report Data. Of course, the good news is that you can define these yourself.
So let's take your example. You want your possible parameter options to be StaffNames.
Create a new dataset in Report Data. It should return all possible staff names for your report.
Something like:-
SELECT DISTINCT
StaffName,
StaffID
FROM
MyReportViewOrTable
Once you have defined this dataset, you should be able to use it as a source of parameter values.

Order data using values stored in another table

I've been using cakephp for a while, but have not learned all the ins and outs yet so I may be missing something simple. Or the problem may lie with my database structure. Either way, if anyone has any idea of what I'm doing wrong, please share.
Is there a way to order the data returned by cakephp's find using values stored in another table?
I am creating custom form fields on a per category basis, so when I choose a particular category to post in, custom fields will be added to my form. I have 3 tables: Posts, Fields, and Answers. The Posts table stores the basic static information for the post, such as id, category_id, title, and description. The Fields table stores the custom field data, such as category_id, field_label, field size, etc. The Answers table stores the values that are entered for particular fields, such as post_id, field_id, value.
I am trying to display the posts for a particular category, and create html table headers on the fly, using select fields, set by a column toggle in the fields table, and also select the answers associated with that particular field and post.
I am able to select all the data I want, and paginate everything just fine, but what I can't seem to figure out is how to order the data using one of the dynamic column values. For example, if I have year, make, and model as 3 custom fields, I would like to click the year column to sort my results by the year values, and if I click the make column, I would like to sort my results by the make values, etc.
I know how to order the results by a particular field inside the posts table, such as id or title, but is it possible to order using the custom fields? Am I setting up the database and/or something else wrong, and if not is there are particular cakephp method or sql command that I need to use in order to sort by the custom fields? I'm not really well versed in complex sql commands.
Thanks.
I'd suggest you pass the field name and sort direction in the URL (GET param). So when you have your table header link, form it so that it links to a URL as so:
http://somesite.com/pages/index/sort:customfield1/dir:asc
Then when you're grabbing the data from the db in your find() query, include the named parameters as the order parameter that can be sent to find.
You'll need to determine a default sorting column and direction. Maybe have that be selectable with a boolean field in the schema -- if there are no parameters sent to the action above, pull the field from your other table that has default set to true in the record.
To clarify: when a user visits a given action, first you'll pull the custom fields from the other table. Then using those fields (either the default as mentioned above, or the named params passed in the URL) form the query for the actual data, using the order parameter.

Resources