USE [namedatabase]
GO
DELETE tblQuerySefareshi
GO
SET IDENTITY_INSERT [dbo].[tblQuerySefareshi] ON 
GO

INSERT [dbo].[tblQuerySefareshi] ([ID], [fldName], [fldQuery]) VALUES (1, N'لیست کالا با تمام جزییات', N'select * from tblkala')
GO
INSERT [dbo].[tblQuerySefareshi] ([ID], [fldName], [fldQuery]) VALUES (2, N'لیست تفصیلی با تمام جزییات', N'select * from tbltafzili')
GO
INSERT [dbo].[tblQuerySefareshi] ([ID], [fldName], [fldQuery]) VALUES (4, N'لیست پرسنل با تمام جزییات', N'select * from tbltafzili where fldcodenoe=''0''')
GO
INSERT [dbo].[tblQuerySefareshi] ([ID], [fldName], [fldQuery]) VALUES (6, N'لیست اشخاص با تمام جزییات', N'select * from tbltafzili where fldcodenoe=''1''')
GO
INSERT [dbo].[tblQuerySefareshi] ([ID], [fldName], [fldQuery]) VALUES (7, N'لیست اسناد', N'	
	SELECT 
    tbl1.fldSanad,
    tbl1.fldCodeTafzili,
    tblTafzili.fldSharheTafzili,
	tbl1.fldMoinKamel,
	tbl1.fldSharheHesab,
    tbl1.fldBedehkar,
    tbl1.fldBestankar,
    tbl1.fldDate,
    tbl1.fldSharh,    
    tbl1.fldType    
FROM 
    (SELECT 
         tblSodooreSanad.fldSanad,
         tblSodooreSanad.fldCodeTafzili,
         tblSodooreSanad.fldBedehkar,
         tblSodooreSanad.fldBestankar,
         tblSodooreSanad.fldRadif,
         tblSodooreSanad.fldCodeSharh,
         tblSodooreSanad.fldDate,
         tblSodooreSanad.fldSharh,
         tblSodooreSanad.fldMoinKamel,
         tblSodooreSanad.fldType,
         tblKolMoin.fldSharheHesab
     FROM 
         tblSodooreSanad 
     INNER JOIN 
         tblKolMoin ON tblSodooreSanad.fldMoinKamel = tblKolMoin.fldCodeHesab
    ) AS tbl1
LEFT JOIN 
    tblTafzili ON tbl1.fldCodeTafzili = tblTafzili.fldCodeTafzili
WHERE 
    tbl1.fldDate BETWEEN tttt1 AND tttt2
	order by fldsanad,fldRadif')
GO
SET IDENTITY_INSERT [dbo].[tblQuerySefareshi] OFF
GO
