Saturday, 15 June 2013

SQL Server Stored Procedure Multiple Condtions -


I have this LINQ C #, which I have to convert to SQL queries. And how many filtering me by circumstances not sure:

  var geofenceReport = companyContext.GeofenceSimpleReports.Where (x = & x gt; x.EnterTime! = Null & amp;. ExitTime! = Null & X.MitsJoofens! = Faucet). Enqueueable (); If (model.GeofenceId! = -1) {geofenceReport = geofenceReport.Where (x => x.iGeofenceId == model.gEofenceId). Enqueueable (); } If (model.AssetId! = -1) {geofenceReport = geofenceReport.Where (x => x.iAssetId == Model. AssetId). Enqueueable (); } If (model.CategoryId! = -1) {geofenceReport = geofenceReport.Where (x = & gt; x.iCategoryId == model.CategoryId) .AsQueryable (); } If (Model SiteId! = -1) {geofenceReport = geofenceReport.Where (x => x.iSiteId == Model SiteId) .AsQueryable (); } GeofenceReport = geofenceReport. Where (x => x.EnterTime> = model.atatatetime and x.timetime = lt; = model. EnddateTime). AKAnable ();  

So that I came to SQL:

I created a new type for AssetId :

  using uSE myDatabase create as tab idTable (ID INT)  

and in SQL:

  use myDatabase process [DBO]. [XPT_GetGeofenceSummaryReport] iiAssetIds idTable, @IGeofenceId INT, @ICategoryId INT, @IAssetId, @IAssetId IiAssetId as INT! = 1 SELECT * to GeofenceSimpleReport WHERE iAssetId (@IAssetIds) IF @IGeofenceId! Select -1 = GeofenceSimpleReport where iGeofenceId = @iGeofenceId @ iCategoryId! GeofenceSimpleReport from = -1 SELECT * where iCategoryId = @iCategoryId IiSiteId! = -1 SELECT * GeofenceSimpleReport where iSiteId = @iSiteId  

and GeofenceSimpleReport is a database view.

But this will not work because it is logically incorrect. It will choose from 4 different GeofenceSimpleReport .

I have to read all code from GeofenceSimpleReport .

And I do not want to temporarily read this data in a table / list in memory because there are so many data in it.

Is there any way to dynamically write this question as I am doing in LINQ?

Text after "div class =" itemprop = "text">

If you are thinking about this more procedurally, and go through a series if-statements Instead of come see a set of your data that you can filter all at once.

You can filter each parameter for which you can provide the value for a filter, EntryTime, ExitTime, etc. on the basic criteria, and then (not -1) then make sure that the ID matches Matches that record in Anything where you have given it will automatically give that value to -1 and that and statement correct

I do this kind of thing all the time by passing in the null standards Are - If they 'non again' non- zero then I would filter them - otherwise they just evaluate the true and passed through

  Use myDatabase GO process [. DBO]. [XPT_GetGeofenceSummaryReport] iiAssetIdIdTable, @IGeofenceId INT, @IsiteId INT, @IAssetId select as INT * is not EnterTime tap where GeofenceSimpleReport and do not have time to get out and zero minutes. GEOFFANCE is not (iAssetId = -1 or iAssetId (@iAssetIds)) and (@iGeofenceId = -1 or iGeofenceId = @iGeofenceId) and (@iCategoryId = -1 or iCategoryId = @ICategoryId) and (@iSiteId = -1 Or iSiteId = @iSiteId)  

No comments:

Post a Comment