So, I am Crystal Report person and am really curious about how I would do this in SQL. I have been searching through stackoverflow and online but haven't found any clear answers that may be applicable (I may just be really slow...)
This seems to be a really simple problem though.
Basically, I am trying to create an attribute called "Vital Status" which is binary in that the person is alive or dead.
To do this, I want to go into our "Activity Status" attribute which contains:
Activity Status: Active main hospital, Active regional hospital, Active consult, Expired
And create a new attribute called "Vital Status" under Crystal formula fields that basically says:
If: Activity Status = "Active main hospital" or "Active regional hospital" or "Active consult"
Then: Vital Status = "Alive"
If: Activity Status = "Expired"
Then: Vital Status = "Dead"
I honestly have no idea how I would do this in SQL say if I wanted to include this in a query like:
SELECT Patient_Name, Disease_status, Date_of_birth, Vital Status
FROM Patient_Info_table
WHERE Disease_status = "diabetes"
This is really simple question and the answer is the same for most DB.
SELECT Patient_Name, Disease_status, Date_of_birth, Vital Status,
case when [Activity Status] in ('Active main hospital', 'Active regional hospital', 'Active consult' Then 'Alive'
else 'Dead' end [Vital Status]
FROM Patient_Info_table
WHERE Disease_status = "diabetes"
Related
I am trying to get all stories and sub-tasks for a specific user along with how much time spent on each item from starting of this year.
I am using JIRA version v8.5.9, where I have tried running the following query but it is not giving me the expected result, any help is appreciated.
(issuetype = "Sub task") AND time spent > 0 and assignee = test123
With your shown samples, attempts please try following JQL query.
(issuetype = "Sub task" OR issuetype = Story )AND timespent > 0 AND assignee = test123 AND createdDate >= startOfYear()
Explanation:
Look for Sub task OR story first.
Then make sure its timespent(looks like OP has a typo in OP's efforts) is more than 0 here.
Then checking assignee should be test123 user.
Then putting AND condition to make sure all items are coming from starting of this current year.
I have little to no experience with access. However, I have managed to create a small recruitment database. I have no experience in coding so please be patient with me!
I am trying to get the status of the candidate to update automatically depending on what stage they are at of the recruitment process. (this may have been answered before but hours of searching i have come up with nothing)
Below i have listed the tables within the database and what field would indicate what status they are at. The tables are in bold and the fields are in []. What the status should be is in " ".
I have the following tables:
Candidate info - This is where the [Status] field is located.
Pre-interview
[Screening date] would suggest this candidate is in "Pre-Interview" State and I have another column which says [interview] This is a yes or no field. If yes, Status would change to "interview". If no, status should change to "closed - NFA(Failed Screening)"
Interview - if in the field [interview date] has been entered the status should remain as "interview" but if another field called:
[Result] = Fail. Status should change to "Closed - NFA (failed interview)"
[Result] = Cancelled. Status Should change to "Closed - NFA (Interview Cancelled"
[Result] = Yes & [Interview Priority] = Low - Status should be "Talent Pipeline"
[Result] = Yes & [interview Priority] = Fast Track - Status should be "fast track".
Onboarding
If the field [date financial approval requested] has a date then the status should change to "In Approval"
Another field called [Approved] = Yes then state should be "Offer Extended" otherwise "Closed - NFA (Offer Declined)"
If it is approved and another field [Result of Contract offer] = Accepted then status should be "Start Date Set" if declined then status should be "Closed - NFA (Offer Declined)"
Deployment
If field [Deployment Date] has a date in it then status should be "Deployment Date Set" otherwise it should state "On Bench"
If the date entered in "deployment date set" has passed then the status should change to "Deployed".
I really hope the above has made sense. I have literally no idea how to implement this and any ideas or help will be much, much appreciated.
Please let me know if further information is required.
Many thanks in Advance!!
Asmaar
We have a user who is receiving reports from SSRS, but who is not listed in the subscription fields (Find report > Manage > Subscriptions). When I query the report server directly, I see them listed in the CC field. The following is the code I found that shows the user in the CC field.
DECLARE
#email VARCHAR(250) = 'user#company.com'
SELECT
cat.[Path],
cat.[Name],
CASE WHEN sub.Description LIKE '%#%' THEN 0 ELSE 1 END AS DDS,
CASE WHEN sub.Description LIKE '%#%' THEN '' ELSE sub.Description END AS DDSDescription,
sub.SubscriptionID,
sub.ExtensionSettings
FROM [ReportServer].[dbo].[Catalog] AS cat
INNER JOIN [ReportServer].[dbo].[Subscriptions] AS sub ON cat.ItemID = sub.Report_OID
WHERE sub.extensionSettings LIKE '%' + #Email + '%'
ORDER BY cat.[Path], cat.[Name]
We have removed and re-created the subscriptions for this report, but they are still receiving the reports. I have confirmed that the user is not part of any of the groups receiving the reports, and there are no forwards enabled that point to their email. I was not able to find anything through google, as most everything I return talks about not receiving valid subscriptions, or users with forwarding enabled.
I inherited these reports, and I am not super SQL savvy. Is it possible that the emails are hard-coded into the report, or is there another location that contains subscription information I could look into?
I'm guessing, but it may be a data driven subscription where email addresses are loaded from database:
Data-Driven Subscriptions
I need to customize a Work Item query in a way that does not seem possible using the very limited WIQL. I have a fairly standard query which needs changing slightly:
<?xml version="1.0" encoding="utf-8"?><WorkItemQuery Version="1">
<TeamFoundationServer>http ://blah-
blah01:8080/tfs/blahcollection</TeamFoundationServer>
<TeamProject>Blah</TeamProject><Wiql>
SELECT
[Microsoft.VSTS.Common.Priority],[System.AreaPath],
[Microsoft.VSTS.Common.Severity],[System.CreatedDate],[System.Id],
[System.WorkItemType],[System.Title],[System.CreatedBy],[System.State],
[System.AssignedTo],[System.ChangedDate],[BLAH.Category],[System.AreaId]
FROM WorkItems
WHERE [System.TeamProject] = #project
and [System.WorkItemType] <> ''
and [System.CreatedDate] >= '2012-01-27T00:00:00.0000000'
and [System.CreatedBy] <> 'blah'
and not [System.State] contains 'Tested'
and not [System.State] contains 'Released'
and [System.State] <> 'Developed'
and ([System.State] <> 'Closed'
and not [System.State] contains 'Resolved')
and [System.AssignedTo] in ('blah1', 'blah2', 'blah3')
ORDER BY
[System.WorkItemType],
[Microsoft.VSTS.Common.Priority],
[System.AreaPath],
[Microsoft.VSTS.Common.Severity],
[System.Id] desc,
[System.AssignedTo]
</Wiql></WorkItemQuery>
It should return the exactly same result as it does now, except that within the [System.AreaPath] column, items containing 'Foo' should appear first, items containing 'Bar' should appear next, and then the rest of the column should be ordered as normal.
This is straight forward enough in T-SQL but seemingly impossible using WIQL so I would appreciate any ideas or workarounds.
Something that may be relevant to the workaround is the unfortunate fact that the TFS instance sits on top of SQLExpress rather than full SQL Server (it was originally a proof of concept and is in the process of being replaced, there's nothing I can do about that at the moment but I still have to sort the query out)
Many thanks
Simon
We've been continuously working on this issue for a few months and not getting far with it. Since this was first asked, we changed the code (based on what the original developer for the site suggested), but we are still not getting where we need to be.
I'm relatively new to Ruby and am currently taking some courses to learn more about it, so please bear with me. We're using Ruby 1.9 and Rails 3.2 We use AS/400 for our database. We've tried using Active Record for this before, and it doesn't want to work because of our versions of Ruby and Rails being older combined with getting it to connect with the 400.
We have an online ordering site that you have to have an account set up to access. Depending on what type of account you are set up as, you might have to have your order approved by someone. I.e. if I am a drop ship account, my distributor has to approve what I'm ordering. The way it had been set up, the distributor wasn't getting any kind of approval email.
Each account that requires approval has x number of email addresses attached to it of people who are able to approve the order. We have been told that target_email needs to be a string, so we tried numerous ways of making it a string to no avail. As is, it's only sending the first two email, not the approval email. If we run target_email = Contact.find_by_sql ["SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"] in console, it returns the expected email addresses associated with that account. So we know that's working the way it should... but we're at a loss as to what is wrong with the rest of the code.
# notify Customer
Mailer.deliver_order_coastal_notify_email("", "Coastal Pet Online Ordering<noreply#coastalpet.com>", "Order Confirmation", email_details)
target_email = Contact.connection.select_values "SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"
# Order Approval
if sign_on.acctypw1.strip == "DS" or sign_on.acctypw1.strip == "DSD"
# If there is no distributor email address, the mailer model will substitute in the admin's email from their settings
target_email.each do | email_address | Mailer.deliver_order_distributor_approval_email(email_address, 'Coastal Pet Online Ordering<noreply#coastalpet.com>', "Order Confirmation Approval", email_details)
end
# notify Coastal staff
Mailer.deliver_order_coastal_notify_email("", "Coastal Pet Online Ordering<noreply#coastalpet.com>", "Order Confirmation-Notify Staff", email_details)
end
I tried
target_email = Contact.connection.select_values("SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 = act223").uniq
This works but it sends emails to multiple accounts why this would happen? I think I need to set a value for act223
act223 = "ACT223"
target_email = Contact.connection.select_values("SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 = #{Contact.connection.quote(act223)}").uniq
this throws NameError (undefined local variable or methodact223' for #):`
in development.log.
Here is a link to the relevant table data if more table information is needed just let me know and I can add it to that page. I am looking to do some sort of a join of a field from another table. In this same model I have SignOn.prefdstw1 which gets me the same account number is there a way to Join this field in the query with the 400?
Any help or suggestions would be greatly appreciated! Thank you in advance!
find_by_sql always returns an array of model objects, so
Contact.find_by_sql ["SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"]
is not an array of email addresses - it's an array of Contact objects, with only one object
You could either extract the email addresses from this, using something like
Contact.find_by_sql(["SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"]).collect do |contract|
contact.emal23
end
I'm not entirely sure what rails will do to the uppercased column name.
If you don't want to instantiate a whole Contact object just to get the email you could also do
Contact.where("ACT223 = ''").pluck('EMAL23')
which would return an array of emails, assuming that Rails knows that the correct table to use for this is WEBOEL23 - it's not clear to me whether that is the table for Contact (and thus you've use set_table_name to configure this) or whether Contact is just a random model unrelated to that table.
You could also drop down a level and do
Contact.connection.select_values "SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 =''"
which will also return an array of email addresses.
Inside the each loop, target_email is a bareword variable (without quotes), but the first argument to the mailer is the string (within quotes) 'target_email'.
Remove those quotes to get to this (whitespace added for readability):
target_email.each do | email_address |
Mailer.deliver_order_distributor_approval_email(
email_address,
'Coastal Pet Online Ordering<noreply#coastalpet.com>',
"Order Confirmation Approval",
email_details
)
end
Then the mailer should have access to the email address.