I have a problem in Crystal reports 11. Because it has limitation to showing the information in dynamic reports and I have a huge list of customer, I want to write a query and ask the first letter of the customer name. If for example, it starts with A, just show the A customers.
this is my query:
select distinct bill_to_code
from TLORDER
where left(BILL_TO_CODE ,1 ) = ?
And CURRENT_STATUS <> 'CANCL'
AND LEFT(BILL_NUMBER , 1 ) NOT IN ('M','U','T','K')
but when I copy this to crystal reports and create a parameter , I get an error
Failed to retrieve data from the database
I should mention that I have another sql query in this report .
It is best to use Stored Procedure when trying to pass a parameter. How to create SP. Then used the SP for your report.
Related
This is my main query of my stored procedure (Sales):
select *
from Customers
where Customers Codes in ('11232133', '654664666',
'243423424', '123123231',
'967868686', '122343245', '636463636')
I want my stored procedure (Sales) connect it with Excel and refresh dynamically (VBA). Instead of customers codes that are contained in the IN clause, I want to show the customer name in the table in Excel and refresh dynamically to stored procedure.
What is the right process?
This is my table in Excel that I want to insert to my stored procedure dynamically:
Customers Codes
324516432
794536703
523682134
943321789
023456763
Thanks in advance!
I have to create and subscribe several SSRS reports based on one single change in the same SQL query.
e.g
SELECT * FROM TABLE1 WHERE value IN (123,456,789)
Report based on the above query should go to the emailaddress1#test.com
Similarly
SELECT * FROM TABLE1 WHERE value IN (111,222,333) - emailaddress2#test.com
SELECT * FROM TABLE1 WHERE value IN (444,555,666) - emailaddress3#test.com
SELECT * FROM TABLE1 WHERE value IN (777,888,999) - emailaddress4#test.com
the change is only in value for every report, and i have to send every report to different email address.
Is there any way to do this other than creating 100's of separate reports ?
You can parameterize the report so that you only have one report, and create a separate subscription with the parameters values for each email address.
I recently updated a Stored Procedure; I changed the last part of it from this:
SELECT
TC.PlatypusDESCRIPTION, TC.MemberName,
TC.WEEK1USAGE, TC.WEEK2USAGE, TC.USAGEVARIANCE,
TC.WEEK1PRICE, TC.WEEK2PRICE, TC.PRICEVARIANCE,
TC.PRICEVARIANCEPERCENTAGE
FROM
#TEMPCOMBINED TC
ORDER BY
TC.PlatypusDESCRIPTION, TC.MemberName;
...to this:
SELECT
TC.PlatypusDESCRIPTION, TC.MemberName, SUM(TC.WEEK1USAGE),
SUM(TC.WEEK2USAGE), SUM(TC.USAGEVARIANCE),
AVG(TC.WEEK1PRICE), AVG(TC.WEEK2PRICE), AVG(TC.PRICEVARIANCE),
SUM(TC.PRICEVARIANCEPERCENTAGE)
FROM
#TEMPCOMBINED TC
GROUP BY
TC.PlatypusDESCRIPTION, TC.MemberName
ORDER BY
TC.PlatypusDESCRIPTION;
to eliminate some duplicate records I was getting (the PlatypusDESCRIPTION and MemberName combination should always appear on one row).
It works just fine from Server Explorer; I can execute the stored procedure, provide the parameters, and it returns the data I expect.
However, the SSRS report that uses this stored procedure no longer works - it leaves the values for all columns from TC.WEEK1USAGE on blank (only the values for PlatypusDESCRIPTION and MemberName display); and when I run it from my custom Winforms app that calls the SP, it gives me an error message about the table not having a field named "" What?!? That field is there, as you can see.
Why would the stored procedure run in Server Explorer, but balk when called from SSRS and elsewhere?
You need to explicitly give the aggregated fields names like this:
SELECT TC.PLATYPUSDESCRIPTION, TC.MemberName, SUM(TC.WEEK1USAGE) AS WEEK1USAGE, SUM(TC.WEEK2USAGE) AS WEEK2USAGE,
SUM(TC.USAGEVARIANCE) AS USAGEVARIANCE, AVG(TC.WEEK1PRICE) AS WEEK1PRICE, AVG(TC.WEEK2PRICE) AS WEEK2PRICE,
AVG(TC.PRICEVARIANCE) AS PRICEVARIANCE, SUM(TC.PRICEVARIANCEPERCENTAGE) AS PRICEVARIANCEPERCENTAGE
FROM #TEMPCOMBINED TC
GROUP BY TC.PLATYPUSDESCRIPTION, TC.MemberName
ORDER BY TC.PLATYPUSESCRIPTION, TC.MemberName;
IOW, "SUM(TC.WEEK1USAGE)" does not cut it; it must be of the form "SUM(TC.WEEK1USAGE) AS WEEK1USAGE" (etc.)
I am using the following SQL query in SSRS:
select s.name, s.studentid, x.section_number
from students s
inner join sections x
on s.studentid=x.studentid
where section_number = :Section
This query produces a list of 10-20 students depending on which 'section' (class) is entered into the :Section parameter. In addition to this, I also want to produce a picture of each student dynamically that matches up with the list.
I have every student's picture on a webserver, and if there's just one value for student then I could use a parameter for StudentID and set the image expression as follows:
="http://website.com/img/" & Parameters!StudentID.Value & ".jpg"
However, I need to have a picture for every student that is returned in the results. Is this possible in SSRS?
Yes it is certainly possible. The problem is you need to have those pictures in the database, in order to return them in the result-set.
You can write a CLR stored procedure that goes and fetches the images, then inserts them into a table in the database. Or a stored procedure that calls a windows/web service that does that.
I have a art-report that does that:
SELECT
[...]
,
ISNULL
(
T_File.Thumbnail
,
CAST
(
0xff[... default image byte-array too large for SO...]
AS varbinary(MAX)
)
) AS RPT_Thumbnail
FROM T_Art
By the way, you can get the image mime-type from the file's extension in SQL
I need to create an SSRS report that is passed a list of parameters and return all the parameters, even if there are no records associated with the parameter. I have posted below of what I am trying to accomplish.
Passed parameters: 12388501, 1238853, 1238858, 123885900, 12388573
And would like the final report to look like the example below:
The parameters passed in this example are Account Numbers. How can I get the Account Number to display as a record even though it is not contained in the database?
I am using SQL Server 2012 database, SSMS for development of the query and will ultimately create the report in SSRS.
I hope my wording of this question makes sense. If there is anything missing in my query please let me know and I will provide it. Thanks in advance!
Step 1: Split your string into rows of a table. My understanding is that Erland Sommarskog is regarded as an authority on handling lists in SQL Server: Arrays and Lists in SQL Server 2008
Using Table-Valued Parameters (revised in 2012. He has a page devoted to the broader topic/earlier SQL Server versions at Arrays and Lists in SQL Server.) There are other methods for splitting strings into table-valued parameters via user-defined functions, etc. that may perform reasonably well for small lists similar to what you have here.
Step 2: using that table-valued parameter that you've populated from the splitting of the string parameter, form your query like the one below. The INNER JOIN in the first SELECT will give you only those records that match an AccountNumber in your inline table and the LEFT OUTER JOIN with the WHERE clause in the second SELECT will give you only AccountNumber values that don't exist in myTable. You can substitute other values for the NULL values I've stubbed in as long as they match the data types of the corresponding fields in myTable.
SELECT mt.AccountNumber,mt.LastName,mt.FirstName,mt.ContactNumber,mt.Address,mt.City,mt.State,mt.Zip
FROM myTable mt JOIN #t t ON mt.AccountNumber = t.AccountNumber
UNION
SELECT t.AccountNumber,NULL LastName,NULL FirstName,NULL ContactNumber,NULL Address,NULL City,NULL State, NULL Zip
FROM #t t
LEFT OUTER JOIN myTable mt ON t.AccountNumber = mt.AccountNumber
WHERE mt.AccountNumber IS NULL