Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

NEED TO BUILT A REPORT LIKE THIS

Posted on 2011-02-18
3
Medium Priority
?
305 Views
Last Modified: 2012-05-11
I HAVE ATTACHED TWO FILES ONE IS REPORT FORMAT AND ONE IS STORED PROC.

NEED HELP TO PASS MULTIPLE DIVSION NAMES IN THE @DIVISIONNAME PARAMETER

LIKE @DIVISIONNAME= 'dIVISION DESCRIPTION 2,DIVISION DESCRIPTION 3'

NOW IT ACCEPTS ONLY ONE LIKE THIS

@DIVISIONNAME= 'dIVISION DESCRIPTION 2'

ITS URGENT PLEASE
rpteBidProjectDetailCosting.pdf
StoredProc.txt
0
Comment
Question by:sqlcurious
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 37

Accepted Solution

by:
ValentinoV earned 2000 total points
ID: 34932500
I think you'll find the answer in the following article: http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/A_2002-Reporting-On-Data-From-Stored-Procedures-part-2.html

It explains in detail how you can pass a multi-valued parameter to a stored procedure, exactly what you're looking for :-)
0
 

Author Comment

by:sqlcurious
ID: 34965671
please check the stored proc too is it possible from this stored proc if not can you modify
0
 
LVL 37

Expert Comment

by:ValentinoV
ID: 34967569
The following code assumes that the function called list_to_tbl as shown in the code snippet below exists.
(Please note: this function differs slightly from the one in the article because you're dealing with strings instead of numbers)

To filter on your divisions, instead of

 set @SQL= @Sql + ' And D.DivisionName LIKE ''%'+@DivisionName+'%''' 

Open in new window


you can do

set @SQL= @Sql + ' And D.DivisionName IN (select * from list_to_tbl(@DivisionName))' 

Open in new window


Please note that the declaration of your @DivisionName parameter should take into account that multiple values are passed.  Which means that the length of the parameter should be: maximum length of division name multiplied by maximum number of divisions that the report user will select.

One more note: I notice that you've also got DivisionIDs in your database.  It would be better if you could set up your parameter to use that ID as value for the parameter.  That way you get a list of comma-separated numbers (as explained in the article referenced earlier) instead of strings.  Obviously that means that your stored proc code would also need to change a bit.
That's just a note though, your method will work too.

Hope this helps?

CREATE FUNCTION list_to_tbl (@list nvarchar(MAX)) 
   RETURNS @tbl TABLE (string varchar(250) NOT NULL) AS 
BEGIN 
   DECLARE @pos        int, 
           @nextpos    int, 
           @valuelen   int 

   SELECT @pos = 0, @nextpos = 1 

   WHILE @nextpos > 0 
   BEGIN 
      SELECT @nextpos = charindex(',', @list, @pos + 1) 
      SELECT @valuelen = CASE WHEN @nextpos > 0 
                              THEN @nextpos 
                              ELSE len(@list) + 1 
                         END - @pos - 1 
      INSERT @tbl (string) 
         VALUES (substring(@list, @pos + 1, @valuelen))
      SELECT @pos = @nextpos 
   END 
  RETURN 
END

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by Valentino Vranken. Introduction: In a previous article (http://www.experts-exchange.com/articles/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Reporting-On-Data-From-Stored-Procedures-part-1.html) I announced that I would writ…
A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27475269.html?cid=1572#a37227028 (htt…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question