Case statement with multiple records - nested

For a requirement I need to create a SQL which should check the data from Table A.
If data exists in table a, query should return that result.
If data doesn't exists on table A, query should check data in table B and return the result.
I tried to use the case statement for this requirement, but I guess case statement is allowed for a single record.
Any help for this is appreciated.
Thanks in Advance.

Related

Couldnt convert to number when expanding a table power query

I have a very annoying problem when i try to merge two tables on power query excel. I use one column to match records from both tables and when i try to expand the second table it pops up the following message:
DataFormat.Error: We couldn't convert to Number.
Λεπτομέρειες:
ECS
I have no idea how to fix this. The columns that are matched have text, not value. There are no errors when i import data. Is there anyone that can help?
Try the following:
Delete the step #"Changed Type" in both queries
Make sure that the two merged columns have the same type (text ABC, in your case)
When you create a query from a table, Power Query try to guess (based on the first 200 lines) the type of each column. Now, the value "Λεπτομέρειες: ECS" is probably included in a different column (than the two merged) that has Number 123 as a type. It's kind of a mixed column (due to the source of data itself or to a delimiter issue).

query does not include the specified expression 'ColB' as part of an aggregate function

I am using this query and it is working perfect but in excel as a database, it is giving me an error of aggregate function -
solution: once I add all column in the group by I don't get sum and Group by doesn't work.
select ColA,ColB,ColC,ColdD,SUM(ColE),ColF,ColG FROM automate GROUP BY ColA
One picture indicates table structure:
Another one is expected output:
Please help me if someone knows- MS-Access / excel as database
Every field in your SELECT part must be either GROUPed BY or aggregated. If all values are guaranteed to be the same or if you don't care which value will be picked use FIRST(), otherwise use the appropriate aggregate function (MIN, MAX, FIRST, LAST, SUM, etc.)
Example:
SELECT ColA, FIRST(ColB), FIRST(ColC), FIRST(ColdD), SUM(ColE), FIRST(ColF), FIRST(ColG) FROM automate GROUP BY ColA

StreamAnalytics Query: How can i write query with if and else statement?

I need conditional output in stream analytics,like i have one lookup data table.while data streaming i need to check in lookup table with if data is exists or not. if data is exists then add data in eg.output1 or if data is not exists then add data in eg.output2.
This if statement is more then 4 or 5 times so multiple query is not possible
You should use CASE statements, sample code from doc and you can modify to meet your needs:
CASE xxx
WHEN xxx THEN yyy
ELSE

SSIS Change data on Import from Excel to SQL Server table

I'm changing all of excel data to numbers before importing to my sql table with SSIS.
This is my original table.
Need to achive this :
Is it possible to do it with SSIS?
In your data flow, you need to provide a translation or mapping from your Source item's value to the target's value. This is generally accomplished through the use of a Lookup Transformation. By default, a Lookup will fail out if no match is found and will perform case sensitive matches so an EX value would not match ex. An example of using the Lookup
Since the lookup gives you the ability to write a query, if you don't have these in a table, you can "cheat" and write the query like
SELECT D.CutId, D.Cut
FROM
(
VALUES
(1, 'EX')
, (2, 'ZZ')
) D(CutId, Cut);

COGNOS make the join conditional between query subjects

In COGNOS, when I create a 1...1 relationship between 2 query subjects A and B, is the relationship always in effect? Or is there a way to say only force the relationship when I am querying A, but when I query B, give me all records from B and ignore A.
This is important because for me, B is a prompt query subject based on a lookup table. so let us say A is a list of all customers and B is a lookup table for Status(Active/Inactive).
When I query B, I just want to see Active/Inactive as prompt values. I select Active and it should bring me only records from A with Active Status.
Is this possilbe?
Cognos uses minimized SQL as default. You can read on it in here:
Cognos - What Is Minimized SQL?
What it basically means is that Cognos picks only the required fields in the SELECT statement.
So, if you picked for prompt values fields from table B, it will only use (for Prompt page only) table B.
When you execute the report assuming you have values from both table A and B, it will do the join

Resources