QlikView How to group by attribute in other table - database

Hello I currently have 2 tables like this:
Parcel which has idParcel,quantityParcel,idProduct
and
Product which has idProduct, nameProduct
When I try to execute Aggr( sum(quantityParcel),[idProduct] ) it works just fine making the sum of quantityParcel by idProduct but when I try to run Aggr( sum(quantityParcel),[nameProduct] ) it just returns the sum of all quantityParcel values without grouping anything, is there any way I can group by nameProduct referencing it from the Product table? The reason I want to do this is because I want to show the actual product name in my dimension instead of just the idProduct number, thanks :)

If you use nameProduct as Dimension why don't just use: sum(quantityParcel)
another option is to use NODISTINCT : Aggr(NODISTINCT sum(quantityParcel),[nameProduct] )

Related

Create a cross reference table using Golden record and associate other records to the record

I have a table where I have ranked all the rows based on the created date column and have the rank indicated on the table as below
main table
I would like to create a cross-reference table with the golden record as the recurring column and the other two records as associated records as below.
output desired
I would like to know how I can achieve this using SQL.
I have tried creating a seperate table with all ID numbers (Rank = 1) and then joining it with the main table to get the ones with rank 1,2 and 3 associated with it. But it doesnt seem to work as I intend to.
output
I have not tested but something like this should work. You might want to add a name_id field.
select b.id_number,a.id_number
from table a
join table b on a.name=b.name
where b.rank=1

SSRS output side by side

Looking at how to output a certain way.
Right now this is how SSRS outputs my table:
Output1
This is how I would like the table to output:
My expected output
Use Matrix and define the field with ID (777xxx) in the column group
I replicated your Data into my local Report. First step you data is something like below
ID CITY PRIMARYORELEMENTARY
7777888 Houston,TX Elementary
7777889 Houston,TX Elementary
7777890 Mumbai,IN Primary
7777891 Delhi,IN Elementary
Now you could so in your SSRS something like below.
Insert and then matrix
After you have matrix then you see matrix as below. Then in column select ID
Now select Rows and then add row inside group below
Now select Primary Element and City in two rows 1 after another.
Once you follow all the steps, below is how you will get your Report

In SQL how to change null values in a view

Hi I have two columns one called BankNo and the other called BranchNo. im running a view that selects the bank numbers along with there branches. One bank doesn't have a branch number so I would like that value to not come up as "null" but to come up as "No Branch". The BranchNo column is a numeric field. Please help
SELECT Coalesce(Cast(BranchNo as varchar(11)), 'No Branch') As BranchNo
...
Coalesce() function: http://msdn.microsoft.com/en-us/library/ms190349.aspx
Try something like this
Select BankNo, ISNULL(Cast(BranchNo as nvarchar(10),'No Branch') from BankTable

Using INDEX in SQL Server

I need to create am index in SQL however it needs to display the records by entering only a part of the name. The index should be created to retrieve the student information using part of the student name (i.e. if the name if Johnanesburg; the user can input John)
I used the syntax below but it wont work
create index Student ON Student(SName)
SELECT * FROM Student WHERE StRegNo LIKE A%
go
I think your problem is here: A%
Try wrapping it in apostrophes.
SELECT *
FROM Student
WHERE StRegNo LIKE 'A%'
Also, you may want a GO statement after you create your index.
The index you are creating over SName will not provide as much benefit for the select statement you are running as one created over StRegNo. Assuming that StRegNo is the primary key on the Student table you could try:
CREATE CLUSTERED INDEX IX_Student on Student(StRegNo)
SELECT *
FROM Student
WHERE StRegNo LIKE 'A%'
However it appears that the SQL you have provided is at odds with your question. If you want to search based on student name then you might want the following instead.
CREATE NONCLUSTERED INDEX IX_Student on Student(SName)
SELECT *
FROM Student
WHERE SName LIKE 'A%'
Ardman got it right regarding your query %A => '%A'. Now as for the index, that's another story that no index can help you with at the time, neither can full text search. If you want to look for names starting with #A (i.e. John%), an ordered index could help but otherwise (i.e. %bur%), you will go for a full table scan !

SQL query join elements

I will re-write my doubt to be more easy to understand.
I have one table named SeqNumbers that have only one column of data named PossibleNumbers, that has value from 1 to 10.000.
Then I have another Table named Terminals and one of the columns have the serial numbers of the terminals. What I want is get all the SerialNumbers that not exists in the Terminals table from 1 to 10.000.
I've created the SeqNumbers table only to do this... maybe there's another solution without using it... that's fine to me.
The query I have is:
SELECT PossibleNumbers from SeqNumbers
Where PossibleNumbers NOT IN (SELECT SerialNumbers from Terminals)**
Basically I want to list ALL serial numbers of terminals that doesn't exists in the database.
This Query works fine I think... but the problem is that I don't want all results in a single column.. I want these results displayed in 4 or 5 columns.
For my purpose I can only use the results from the query like that. I cannot use programmatically methods to do that.
Hope this is more clear now... Thanks for all the help...
select x, x+1000 from tablename
Will that do it for you?
If I'm reading this right, you'd probably have to do a self join; something like:
SELECT
LeftValues.ColA,
RightValues.ColA AS ColB
FROM YourTable LeftValues
LEFT JOIN YourTable RightValues ON LeftValues.ColA = RightValues.ColA - 1000
WHERE LeftValues.ColA < 1000
Note: Use the JOIN that makes sense for you (left if you are willing to accept NULLs in ColB, inner if you only want them where both values exist)
You can use a scripting language to parse the MySQL results to format it anyway you like. Are you using PHP to access the database? If so, let me know and I can cook one up for you.
I just saw your new updated question. In this case the order of the columns will be ordered by your SELECT statement and you can also sort too. Here is an example:
SELECT Column1, Column2 FROM my_table ORDER BY Column1, Column2 ASC

Resources