2
Answers

Setdatasource to Crystal Report

Photo of Bil Al

Bil Al

15y
6.9k
1
Hello Everybody
i use a crystalReport in C# 2008 with SQL 2005
the problem is when i try to sned the Dataset to my crystalreport 

crystalreportName.SetDataSource(Mydataset.Tables[
"MyTables"]);
this line take 60 sec in some computer in first call only
but if i use this code after it run normally 
i have this problem in my computer but not in my laptop
i try hardly to know what is the difference  between them  but i cant find it
if some one have any idea about this problem  i ll apperciate any help
thanks
 

Answers (2)

0
Photo of Siva Tiyyagura
NA 26 4 8y

Assuming yout Table1 will have all working day timings(except for leaves) and Table2 will have Leaves information Below TSQL can give you the required result.
SELECT * INTO #Temp
FROM
(
SELECT
[empid]
,[attdate] AS [Date]
,CAST(DAY([attdate]) AS VARCHAR(2))+ '(' +CAST([attdate] AS VARCHAR(25))+')' AS [Day]
,'Status' = CASE WHEN [ workedhours] > 8 THEN 'P' ELSE 'AB' END
FROM [Table1]
UNION
SELECT
[empid]
,[leavedate] AS [Date]
,CAST(DAY([leavedate]) AS VARCHAR(2))+ '(' +CAST([leavedate] AS VARCHAR(25))+')' AS [Day]
,'Status' = 'L'
FROM [Table2]
) AS [Result]

SELECT DISTINCT [Date],[Day] INTO #Temp2 FROM #Temp ORDER BY [Date]

DECLARE @ColumnNames NVarchar(MAX)
DECLARE @SqlQuery NVARCHAR(max)

SELECT @ColumnNames=STUFF((
select ',['+ [Day] +']'
from #Temp2
FOR XML PATH('')
)
,1,1,'')

SET @SqlQuery = N'SELECT [empID],' + @ColumnNames +' FROM (Select [EmpId],[Day],[Status] From #Temp) P Pivot (MAX([Status]) For [Day] in (' +@ColumnNames+'))AS PivotTable;'

EXEC Sp_executeSql @SqlQuery