Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have problem with this stored procedure and i can not create RDLC report fromthat please help me. thanks.
SQL
USE [mystored]
GO
/****** Object:  StoredProcedure [dbo].[Sp_RepReceptionServicesParts]    Script Date: 04/13/2016 11:16:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




ALTER procedure [dbo].[Sp_RepReceptionServicesParts]
    (
     @UserType as char(1),
     @UserCode as varchar(5),
     @DateFrom as varchar(10),
     @DateTo as Varchar(10) ,
     @DealerNo as varchar(5),
     @DealerNoCombo as varchar(5),
     @VehicleCode as varchar(5) ,
     @ChassisNo as varchar(30),
     @ReceptionCode as varchar(10),
     @FactorNo as varchar(10),
     @ServiceUserCode as varchar(30),
     @PartNo as varchar(30) ,
     @CostCenter as char(1) ,
     @PartOrService as char(1),
     @ReceptionType as char(1),
     @VehicleType as char(1)
    )
as
begin

declare @strParts as varchar(max)
declare @strServices as varchar(max)
declare @strFinal as varchar(max)
set @DateFrom = '''' + @DateFrom + ''''  
set @DateTo = '''' + @DateTo + ''''  
set @strParts =  '
                select ReceptionCode,RecDate,FactorNo,rp.DeliverDate FactorDate,VehicleFarsiName VehicleName, case when s.Imported = 1 then ''notok'' else ''ok'' end as VehicleType ,RecKilometer ReceptionKilometer, ''Parts'' as Type,
                        PartFarsiName as Name,''-'' as ServerName,PartNo as Code, Warranty=case HasWarranty when 1 then ''Yes'' when 0 then ''No'' end,
                        max(UnitPrice) UnitPrice,sum(Number) Qty,Sum(ExtraPrice) ExtraPrice,Sum(SpecialDiscount) Discount, Sum((UnitPrice*Number)+ExtraPrice - SpecialDiscount ) as Price ,ChassisNo,MotorNo,s.ActualDeliveryDate ''date start''
                from V_RecParts rp 
                        left join 
                        V_LastSubscribers s 
                        on rp.SubScriberCode = s.SubScriberCode
                where RecDate  between ' + @DateFrom + ' and ' + @DateTo + ' --DealerNoRMN --VehicleCodeRMN --ChassisNoRMN --ReceptionCodeRMN --FactorNoRMN
                        --PartNoRMN --CostCenterRMN --ReceptionTypeRMN --VehicleTypeRMN
                group  by ReceptionCode,RecDate,FactorNo,rp.DeliverDate,VehicleFarsiName,RecKilometer,HasWarranty,PartFarsiName,PartNo,ChassisNo,MotorNo,s.ActualDeliveryDate, s.imported '

                    set @strServices = '
                select ReceptionCode,RecDate,FactorNo,rs.DeliverDate FactorDate,VehicleFarsiName VehicleName, case when s.Imported = 1 then ''notok'' else ''ok'' end as VehicleType,RecKilometer ReceptionKilometer, ''Services'' as Type,
                        FarsiName as Name,ServerName,ServiceUserCode as Code, Warranty=case HasWarranty when 1 then ''Yes'' when 0 then ''No'' end,
                        max(UnitPrice) UnitPrice,sum(Number) Qty,Sum(ExteraPrice) ExtraPrice,Sum(SpecialDiscount) Discount, Sum((UnitPrice*Number)+ExteraPrice - SpecialDiscount ) as Price ,ChassisNo,MotorNo,s.ActualDeliveryDate ''date start''
                from V_RecServices rs 
                        left join 
                        V_LastSubscribers s 
                        on rs.SubScriberCode = s.SubScriberCode
                where RecDate  between ' + @DateFrom + ' and ' + @DateTo + ' --DealerNoRMN --VehicleCodeRMN --ChassisNoRMN --ReceptionCodeRMN --FactorNoRMN
                        --ServiceUserCodeRMN --CostCenterRMN --ReceptionTypeRMN --VehicleTypeRMN
                group  by  ReceptionCode,RecDate,FactorNo,rs.DeliverDate,VehicleFarsiName ,RecKilometer ,HasWarranty,FarsiName,ServerName,ServiceUserCode,ChassisNo,MotorNo,s.ActualDeliveryDate,s.imported '   
if @PartOrService = 'P' -- output is just Parts
    set @strFinal = @strParts
else
    if @PartOrService = 'S' -- output is just Services
        set @strFinal = @strServices
    else
        set @strFinal = '( '+ @strParts + ') union ( ' + @strServices + ' ) '

set @strFinal = @strFinal + ' order by ReceptionCode '

if @UserType <> 'A' 
    set @strFinal = replace(@strFinal ,'--DealerNoRMN', ' and ReceptionCode / 100000 = ' + @DealerNo )
else
    if @DealerNoCombo <> -1
        set @strFinal = replace(@strFinal ,'--DealerNoRMN', ' and ReceptionCode / 100000 = ' + @DealerNoCombo )
    else
        set @strFinal = replace(@strFinal ,'--DealerNoRMN', '' )

if len(@vehicleCode) > 0 
    set @strFinal = replace(@strFinal ,'--VehicleCodeRMN', ' and VehicleCode = ' + @vehicleCode )
else
    set @strFinal = replace(@strFinal ,'--VehicleCodeRMN', '' )

if len(@ChassisNo) > 0 
    set @strFinal = replace(@strFinal ,'--ChassisNoRMN', ' and ChassisNo like ''%' + @ChassisNo + '%''' )
else
    set @strFinal = replace(@strFinal ,'--ChassisNoRMN', '' )

if len(@ReceptionCode) > 0 
    set @strFinal = replace(@strFinal ,'--ReceptionCodeRMN', ' and ReceptionCode = ' + @ReceptionCode )
else
    set @strFinal = replace(@strFinal ,'--ReceptionCodeRMN', '' )

if len(@FactorNo) > 0 
    set @strFinal = replace(@strFinal ,'--FactorNoRMN', ' and FactorNo = ' + @FactorNo )
else
    set @strFinal = replace(@strFinal ,'--FactorNoRMN', '' )

if len(@PartNo) > 0 
    set @strFinal = replace(@strFinal ,'--PartNoRMN', ' and PartNo like ''%' + @PartNo + '%''' )
else
    set @strFinal = replace(@strFinal ,'--PartNoRMN', '' )

if len(@ServiceUserCode) > 0 
    set @strFinal = replace(@strFinal ,'--ServiceUserCodeRMN', ' and ServiceUserCode like ''%' + @ServiceUserCode + '%''' )
else
    set @strFinal = replace(@strFinal ,'--ServiceUserCodeRMN', '' )

if @CostCenter = 'G'      -- output is just guaranty
    set @strFinal = replace(@strFinal ,'--CostCenterRMN', ' and HasWarranty = 1' )
else
    if @CostCenter = 'C'  -- output is just Customer
        set @strFinal = replace(@strFinal ,'--CostCenterRMN', ' and HasWarranty = 0' )
    else              -- 'B' output is Customer and guaranty
        set @strFinal = replace(@strFinal ,'--CostCenterRMN', '' )

if @ReceptionType = 'C'  -- output is just Closed Reception
    set @strFinal = replace(@strFinal ,'--ReceptionTypeRMN', ' and QCFlag = 1 and FactorNo is not Null' )
else
    if @ReceptionType = 'O'  -- output is just Open Reception
        set @strFinal = replace(@strFinal ,'--ReceptionTypeRMN', ' and (QCFlag = 0 or FactorNo is Null)' )
    else
        set @strFinal = replace(@strFinal ,'--ReceptionTypeRMN', '' )

if @VehicleType = 'F'  
    set @strFinal = replace(@strFinal ,'--VehicleTypeRMN', ' and s.Imported = 0 ' )  -- Imported = 0 --> Factory
else
    if @VehicleType = 'N'  
        set @strFinal = replace(@strFinal ,'--VehicleTypeRMN', ' and s.Imported = 1 ' ) -- Imported = 1 --> Not Factory
    else
        set @strFinal = replace(@strFinal ,'--VehicleTypeRMN', '' )

--print @strFinal
exec (@strFinal)

SQL
end




0
down vote
accept
i can show data in to datagridview by this code:

public DataTable MySelect(string UserType,string UserCode,string DateFrom,string DateTo, string DealerNo,string DealerNoCombo,string VehicleCode,string ChassisNo,string ReceptionCode, string FactorNo,string ServiceUserCode,string PartNo,string CostCenter,string PartOrService, string ReceptionType, string VehicleType, string HasWarranty) {

if (openConnection() == true)
{
Cmd = new SqlCommand("Sp_MyFullShowing", Con2);
//Cmd.CommandText = "Sp_MyFullShowing";
Cmd.Parameters.AddWithValue("@UserType", UserType);
Cmd.Parameters.AddWithValue("@UserCode", UserCode);
Cmd.Parameters.AddWithValue("@DateFrom", DateFrom);
Cmd.Parameters.AddWithValue("@DateTo", DateTo);
Cmd.Parameters.AddWithValue("@DealerNo", DealerNo);
Cmd.Parameters.AddWithValue("@DealerNoCombo", DealerNoCombo);
Cmd.Parameters.AddWithValue("@VehicleCode", VehicleCode);
Cmd.Parameters.AddWithValue("@ChassisNo", ChassisNo);
Cmd.Parameters.AddWithValue("@ReceptionCode", ReceptionCode);
Cmd.Parameters.AddWithValue("@FactorNo", FactorNo);
Cmd.Parameters.AddWithValue("@ServiceUserCode", ServiceUserCode);
Cmd.Parameters.AddWithValue("@PartNo", PartNo);
Cmd.Parameters.AddWithValue("@CostCenter", CostCenter);
Cmd.Parameters.AddWithValue("@PartOrService", PartOrService);
Cmd.Parameters.AddWithValue("@ReceptionType", ReceptionType);
Cmd.Parameters.AddWithValue("@VehicleType", VehicleType);
Cmd.Parameters.AddWithValue("@HasWarranty", HasWarranty);


Cmd.CommandType = CommandType.StoredProcedure;

DT = new DataTable();
Adapter = new SqlDataAdapter(Cmd);
Adapter.Fill(DT);
closeConnection();
}
return DT;
}

and in button click this code:

dt = sql.MySelect("", "", lbl1.Text, lbl2.Text, "", "", "", "", txtPaziresh.Text, "", "", "", "", "", "", "", cmbGarant.Text); elDataGridView3.DataSource = dt.DefaultView;

but i can not create rdlc report from that. anyone can not helppppppp????

What I have tried:

I have problem with this stored procedure and i can not create RDLC report fromthat please help me. thanks.
Posted
Updated 13-Apr-16 2:33am

1 solution

You will not get columns details in RDLC report because you are using dynamic query.
you can do like Below :

1. Before making report comment your dynamic query.
2. Make a new query(don't make this query dynamic) with the same fileds as mention in dynamic query.
3. execute procedure.
4. Now use this procedure in your report.
5. here you will see all your fields which you mention in your procedure in new query.
6. Now remove/comment your new query and uncomment your dynamic query.
7. execute procedure.

Then run your program or reports you will find your result.


Ashish
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900