I have a SQL-based question. when I run the select statement in my table it shows in one line but when I print it, it comes in multiple rows. because of this when I create SSRS report the data shows in multiple rows.
eg: SQL select statement result:
HYDROCARBON CONSTRUCTION CO % L H GUNN PO BOX 53495 HOUSTON TX 77052-3495
and when I filter by the WHERE clause I did not get any result.
eg: select emplpyer_name from employers where employer_name = 'HYDROCARBON CONSTRUCTION CO % L H GUNN PO BOX 53495 HOUSTON TX 77052-3495'
but when I print it, it gives results in four rows like below.
I have run the bolow code and got 4 line result. but I want it in one line when I print it:
declare #t varchar(1000);
set #t=(SELECT Employer_name as a from EMPLOYERS where e_name like 'HYDROCARBON CO%');
print #t;
HYDROCARBON CONSTRUCTION CO
% L H GUNN
PO BOX 53495
HOUSTON TX 77052-3495
it is the address column and I am not able to get this result when I filter by the WHERE clause as well. it shows blank. I want all these multiple rows in one line when I print as well.It would be appreciated if someone helps me with this.
and SSRS result I got like below.
enter image description here
I have tried to concatinate it but still gave multiline result.
Related
I am looking to automate a process which has a sales dataset and a specific column named SALES CODE which is of 5 letters.
Based on the input given by the user I would like to filter the data but the problem is the user can give multiple sales codes and sometimes the length of codes could be 5,4,3,2 or 1 based on the condition. How will I filter out the required rows based on the above condition?
SALESCODE area value units rep
A10AA KR 100 10 Jay
B10AQ TN 120 12 Jrn
C10AH KR 200 10 Jay
T11TA TR 180 10 Jay
Say if I give the input as A10AA, B10A, T11 I should be able to
Get the sales data with codes A10AA, B10AQ, T11TA. kindly help.
Use the IN operator. Since you want to match values that start with the specified value use the : modifier. Since your values are character values make sure to include quotes.
proc print data=sales_data ;
where salescode in: ("A10AA" "B10A" "T11");
run;
If you want you can use commas between the values in the list, but I find it easier to type spaces instead.
Here I am trying to get the record for my products where the # swab location in Main table matches the count of swab locations in swab Table and Users can checked off the Y/N to verify that the description of the locations are correct.
Here is the example of my 2 tables.
tblMainEquipment
Asset_ID EquipmentName Num_SwapLocations Verified
234 Saijimon 2 N
235 Pasquale 3 N
tblMainSwapLocations
Asset_ID Swap_location
234 Particle Cannon
234 RailGun
235 Particle Cannon
I use the following query to count the number of records, i avoided using a having query to combine both tables since it is not updatable.
qryMainSwapLocationCount
SELECT MSL.Asset_ID, Count(Asset_ID) AS [Count]
FROM tblMainSwapLocation AS MSL
GROUP BY MSL.Asset_ID;
This will give me the result of
qryMainSwapLocationCount
Asset_ID count
234 2
234 1
I used the following as a record source for my form to allow users to verify the inputs.
SELECT MEQ.Asset_ID, MEQ.Equipment_Name,MEQ.Num_swapLocations MEQ.Verified
FROM tblMainEquipment AS MEQ, qryMainSwapLocationCount AS MSLC
WHERE (((MEQ.Asset_ID)=[MSLC].[Asset_ID]) AND ((MEQ.Num_SwapLocations)=[MSLC].[Count]);
This result would be
tblMainEquipment
Asset_ID EquipmentName Num_SwapLocations Verified
234 Saijimon 2 N
However this record set is not editable. Is there any reasons for this?
I think you should put your table tblMainEquipment as your recordsource and bring all the fields from that on to your form:
Then insert an unbound textbox (perhaps close to your Num_SwapLocations field for easy comparison):
Then in this new textbox, put the following in the ControlSource:
=DCount("ASSET_ID","tblMainSwapLocations","ASSET_ID=" & [Asset_ID])
Then open your form and it should count the number of records in table tblMainSwapLocations that have the same Asset_ID as the record currently showing:
You'll then be able to update the Verified field in your tblMainEquipment table.
I have a requirement, where from front end (JSP)
If market is selected, sectors mapped to Markets have to populate
Likewise, based on sector value selected, End Equipment has to
populate.
Market --1st Drop down
Sector --2nd Drop down
Webcategory -- 3rd Drop down
So initially for getting this page, there will be a database hit,
so as oracle DB developer, I have to send OUT parameter containing this mapping.
End Equipment mapped to Sector and mapped to Market.
I am using below query which is not giving my result as required.
SELECT C.MARKET_SEGMENT_NAME,
C.MARKET_SEGMENT_ID,
B.SECTOR_NAME,
B.SECTOR_ID,
A.WEB_CATEGORY_NAME,
A.WEB_CATEGORY_ID
FROM MSE_WEB_CATEGORY_MASTER A,
MSE_SECTOR_MASTER B,
MSE_MARKET_SEGMENT_MASTER C
WHERE C.MARKET_SEGMENT_ID = B.FK_MARKET_SEGMENT_ID
AND B.SECTOR_ID = A.FK_SECTOR_ID(+);
Output:
MARKET_SEGMENT_NAME MARKET_SEGMENT_ID Sector Sector_id WEB_cate Web_category_id
GOOGLE 90 Slawn 1 FLIPKART 1
BING 100 Clown 2 SNAPDEAL 2
YAHOO 110 VERICON 4 AMAZON 3
YAHOO 110 VERICON 4 E-KART 4
YAHOO 110 QUALCOMM 3
Expected Output:
MARKET_SEGMENT_NAME-MARKET_SEGMENT_ID-SECTOR_NAME-SECTOR_ID-WEB_CATEGORY_NAME-WEB_CATEGORY_ID
GOOGLE-90-Slawn-1-FLIPKART-1
BING-100-Clown-2-SNAPDEAL-2
YAHOO-110-VERICON-4-AMAZON-3
YAHOO-110-VERICON-4-E-KART-4
YAHOO-110-QUALCOMM-3
so that I can send this combination as an Output parameter from my procedure.
Since there is a restriction for not to have DB queries in JSP/presentation layer, everything is been done on DB layer.
I agree with #Ben. Your query appears to return the required data. Concatenating the values into a dash-separated string is a task for the display layer.
Having said that, here is a solution which does what you ask for. || is the concatenation operator. The NVL2() function handles the outer-joined columns, and suppresses the dash when they're blank.
SELECT C.MARKET_SEGMENT_NAME
||'-'||C.MARKET_SEGMENT_ID
||'-'||B.SECTOR_NAME
||'-'||B.SECTOR_ID
||nvl2(A.WEB_CATEGORY_NAME,'-'||A.WEB_CATEGORY_NAME,null)
||nvl2(A.WEB_CATEGORY_ID,'-'||A.WEB_CATEGORY_ID,null) concat_str
FROM MSE_WEB_CATEGORY_MASTER A,
MSE_SECTOR_MASTER B,
MSE_MARKET_SEGMENT_MASTER C
WHERE C.MARKET_SEGMENT_ID = B.FK_MARKET_SEGMENT_ID
AND B.SECTOR_ID = A.FK_SECTOR_ID(+);
I have a table of zip codes and a stored procedure to calculate all zipcodes within an X radius, given a zip code and a radius.
For example, to find all zip codes within 200 miles of 10001 I'd enterCALL zip(10001,200) and it would display each zip code.
In a new column "hradius", I would like to have all zip codes within 200 miles of that row's zip code.
I'm very new to SQL, thank you for any help.
Don't shove a string with multiple values into one field. Create a related table to link one zip code to multiple:
ZipOrigin ZipDest Distance
12345 23456 150
12345 34567 175
...
(Distance is optional - for example you could use it to find all zip codes within ANY radius less than X)
In this situation, if you want to pre-generate your list of matches, you're much better off using a separate table for the matches. You'll have two tables: one for your zip codes and one for the matches. The second table will have two columns, one for the source zip code and one for the matching zip code within X miles (200 in this case). There will be a separate row for each match. The results from the stored procedure should output to the second table. Once you have that you can use a query like the following:
SELECT zip.zipcode, zipJoin.zipcode
FROM zipCodes zip
INNER JOIN zipCodeMatches zipJoin
ON zip.zipcode = zipJoin.sourceZipCode
WHERE zip.zipcode = #zip
You should spend some time learning about proper table design and normalization and how to join tables together to help you understand these concepts.
I'm new to working with SQL Server 2005 Reporting Servives using RDLs in BIDS.
I need to modify an existing report so that I can merge cells in adjacent rows which would have the same value for that particular column.
Ex: consider this is the table returned from the stored procedure used by the reports RDL.
_________________________________________________
Id SubCategory Field1 Field2 Total
_________________________________________________
1 a Bob US 17
1 b John UK 17
2 a Mary AUS 12
3 d Ram IND 19
4 b Alex UK 09
4 c Abby FR 09
5 e Tim IT 03
_________________________________________________
Table Example - Couldn' Format Text :( Image here : http_://i.stack.imgur.com/gWEH5.png_
What I need to do is I want the cells merged into one where two adjacent rows in the same column have the same value.
Like Id 1 is repeated twice, so the cells for these must be merged. (Also 4)
Similarly for the last column Total for cells with Ids 1 and 4 must be merged.
The RDL has "TextBox" for columns, I saw some other questions in this forum but were related to Tablix or Matrix, so I thought it would be better if I mentioned it.
I need this merging to be done in the RDL, and this should also be present when exported to Excel.
Hoping someone will be able to help soon.
Change the SQL query to use a group by on ID.
in reporting services drag Id On Row group Of Tablix Upaer than Detail Group
and drag other Fields(except Total) Besid ID and befor vertical dash line In the table.
and drag Total to first cell afte vertical dash line