Thursday, August 26, 2010

USING RECURSIVE COMMON TABLE EXPRESSIONS TO REPRESENT TREE STRUCTURES

Problem : 
Suppose if you have table structure which contains reference as same table for parent entry and you want to display data in table structure then below query will be useful.

Table Structure is:-
catid       catname                parentcatid
1             Cat1                     0
2             Cat2                     0
3             Cat3                     0
4             Cat1_sub1            1
5             Cat1_sub2            1
6             Cat1sub_sub         4
7             Cat2_sub1            2
8             Cat3_sub1            3
9             Cat2_subsub         7
10           Cat2_subsub         6

Desired output is:
Parentcatid                   Tree_Structure
0                                  Cat1
1                                  Cat1->Cat1_sub1
4                                  Cat1->Cat1_sub1->Cat1sub_sub
6                                  Cat1->Cat1_sub1->Cat1sub_sub->Cat2_subsub
1                                  Cat1->Cat1_sub2
0                                  Cat2
2                                  Cat2->Cat2_sub1
7                                  Cat2->Cat2_sub1->Cat2_subsub
0                                  Cat3
3                                  Cat3->Cat3_sub1

SQL Query:-

WITH supplytree AS
(SELECT catid, catname, parentcatid, CAST(catname As varchar(1000)) As si_item_fullname
FROM #tempsample
WHERE parentcatid = 0 
UNION ALL
SELECT si.catid,si.catname,
si.parentcatid,
CAST(sp.si_item_fullname + '->' + si.catname As varchar(1000)) As si_item_fullname
FROM #tempsample As si
INNER JOIN supplytree AS sp
ON (si.parentcatid = sp.catid)
)
SELECT parentcatid, si_item_fullname
FROM supplytree
ORDER BY si_item_fullname;

Wednesday, August 25, 2010

In SQL Server, How to combine multiple row result into one row

Suppose You have below data
Subjectid   Name
1               XYZ
1               ABC
1               PQR
2               RPA
2               PBA
3               TGB

Expected Result :
Subjectid  Name
1              XYZ, ABC, PQR
2              RPA, PBA
3              TGB


SQL Query:
Select Main.SubjectID,
Left(Main.Students,Len(Main.Students)-1) As "Students"
From(Select distinct ST2.SubjectID,
(Select ST1.Name + ',' AS [text()]
From dbo.Students ST1
Where ST1.SubjectID = ST2.SubjectID
ORDER BY ST1.SubjectID
For XML PATH ('')) [Students]
From dbo.Students ST2) [Main]

Tuesday, August 17, 2010

System.Runtime.Serialization.Json namespace is missing

You need to add reference of below dlls

System.Runtime.Serialization.dll
System.ServiceModel.dll
System.ServiceModel.Web.dll

Monday, August 16, 2010

Sharepoint - Apply Forms Authentication

http://technet.microsoft.com/hi-in/windowsserver/sharepoint/dd355701(en-us).aspx
http://www.simple-talk.com/dotnet/windows-forms/configuring-forms-authentication-in-sharepoint-2007/

Twitter Integration with asp.net

http://www.stardeveloper.com/articles/display.html?article=2009061701&page=1

Thursday, July 29, 2010

Sharepoint

http://sarangasl.blogspot.com/2009/09/custom-sharepoint-webparts.html
http://www.codeproject.com/KB/sharepoint/SharePointBasics.aspx#SP2007

Tuesday, May 18, 2010

security Exception solution

Error:-

Server Error in '/' Application. Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.


Solution:-
changing the App pool identity to NetworkService / aspnet fixed it.
Additionally, enabling Load User Profile on the app pool also worked.