Friday 27 June 2014

ssrs show hide column based on expression


I have two columns and column name ename,epname
my requirement will be if all the rows has same value of ename=epname than I dont want to display two columns
if any one of the row value is not equal i.e ename<>epname than I want to dispay these two columns
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[empdetails]') AND type in (N'U')) DROP TABLE [dbo].[empdetails] GO
CREATE TABLE [dbo].[empdetails]( [eid] [int] IDENTITY(1,1) NOT NULL, [ename] [varchar](20) NULL, [epname] [varchar](20) NULL)
GO
INSERT INTO empdetails values('ra','ra')
GO
INSERT INTO empdetails values('ra','rag') GO
select * from empdetails
Create a dataset in ssrs report and drag all columnn in table
go to column visibilty set column visibility
show or hide based on an expression
set expression "=iif(sum(iif(Fields!ename.Value<>Fields!epname.Value,1,0),"DataSet1")>0,false,true)"
where "DataSet1" your dataset name

Friday 13 September 2013

Dynamically mapping source and destination table and column information and load from souce to destination,how to use Microsoft.SqlServer.TableTransferGeneratorTask

To achieve this task (Dynamically map source and destination table in XML file) we can use the task Microsoft.SqlServer.TableTransferGeneratorTask

  1. I am going to load the table data from source server to destination server without creating dataflow task in ssis package
  2. all table, column mapping I am going to configured in XML file like
    •  source table name and destination table name
    •  source column name and destination column name
    •  column length
    • column data type
  3. I am going to use Microsoft.SqlServer.TableTransferGeneratorTask  to achieve this task(Its       Microsoft task)
  4. Please execute this script in any sql server database server
create database dbSource
go
create database dbDestination
go
use dbSource
go
Create Table Test(emp_id int)
go
insert into Test values (10)
insert into Test values (20)
insert into Test values (30)
go
Create table SourceSoaps (sSoapName varchar(20),sSoapCost decimal(15,4))
go
insert into SourceSoaps values('santoor',20.02)
insert into SourceSoaps values('mysoresand',50.23)
insert into SourceSoaps values('deve',852.02)
go
use dbDestination
go
Create Table Test(emp_id int)
go
Create table DestinationSoaps (dSoapName varchar(20),dSoapCost decimal(15,4))

Thursday 17 November 2011

How to replace database name in 100 sql script files

Hi I have 100 sql files.. in that I need replace database name xyz to abc..
Some the table name specified as xyz.<tablename> to abc.<tablename> in all the files and full content using ssis?

Approach:
1)use foreach loop and enumerator file...

and expressions specify as *.sql and give folder name where sql files exist.

in for each loop assign a varible to result to get file name

use script task in foreach loop

then

public
{


void Main()String ErrInfo = "";String FilePath = Dts.Variables["User::filename"].Value.ToString();try{
String FileContent; //Variable to store File ContentsFileContent = ReadFile(FilePath, ErrInfo);

{
Dts.Log(
Dts.Log(ErrInfo, 0,
Dts.TaskResult = (

}

WriteToFile(FilePath, FileContent, ErrInfo);if (ErrInfo.Length > 0)"Error while writing File " + FilePath, 0, null);null);int)ScriptResults.Failure;return;catch (Exception e)null);int)ScriptResults.Failure;public String ReadFile(String FilePath, String ErrInfo)String strContents;StreamReader sReader;try{
sReader =
strContents = sReader.ReadToEnd();
sReader.Close();

}

{

ErrInfo = e.Message;

}
}

{

File.OpenText(FilePath);return strContents;catch (Exception e)MessageBox.Show(ErrInfo);return "";public void WriteToFile(String FilePath, String strContents, String ErrInfo)StreamWriter sWriter;try{
sWriter =
sWriter.Write(strContents);
sWriter.Close();
}

{

ErrInfo = e.Message;
}
}
new StreamWriter(FilePath);catch (Exception e)MessageBox.Show(ErrInfo);

{
Dts.Log(
Dts.Log(ErrInfo, 0,
Dts.TaskResult = (

}
}

{
Dts.Log(e.Message, 0,
Dts.TaskResult = (
}
}

{


if (ErrInfo.Length > 0)"Error while reading File " + FilePath, 0, null);null);int)ScriptResults.Failure;return;FileContent = FileContent.Replace("LAjit", "Feature1BLajit");

Friday 30 September 2011

[OLE DB Source [1]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x00040EDA Description: "Warning: Null value is eliminated by an aggregate or other SET operation.".

[OLE DB Source [1]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 10.0"  Hresult: 0x00040EDA  Description: "Warning: Null value is eliminated by an aggregate or other SET operation.".
 The SSIS package has failed when the oledb datasource query dynamically building..

Resoution:
ADD this query
SET ANSI_WARNINGS OFF