Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Setting columns during a SELECT
Message
De
22/12/2008 09:45:57
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
22/12/2008 09:44:37
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01369088
Message ID:
01369126
Vues:
10
>Hi Borislav,
>
>Since records are being added fairly continuously, I am concerned the update could potentially affect a different set of records than the original select. If there isn't a way to update the existing selection, then I could probably update the returned dataSet and update those. This just means a second round trip to the server which is accross a wire.
>
>also, I see you used a different join for the two tables than I, is that more efficient?
>Thanks

Oh, duh I could just turn that around and do the update first and then select the ones I updated based on that SentinelMark. Do you see anything wrong with that?
>
>>>Hi All,
>>>
>>>I am creating a stored procedure that selects a subset of records from a table. I would like to set the value of three columns when I make the selection. How can I do this? Here is my stored procedure.
>>>
>>>
>>>CREATE PROCEDURE dbo.GetSpotsByCompanyIDWithRange
>>>(
>>>	@CompanyID UniqueIdentifier,
>>>	@StartRange DateTime,
>>>	@EndRange DateTime,
>>>	@Sentinel Bit,
>>>	@SentinelMark VarChar
>>>) 
>>>AS
>>>BEGIN
>>>	SET NOCOUNT ON;
>>>
>>>	SELECT     s.Track_Id,
>>>		s.CompanyID,
>>>		s.TruckID,
>>>		t.TruckCode,
>>>		s.DriverID,
>>>		s.Truck_Ip,
>>>		s.IsTip,
>>>		s.Spot_Message,
>>>		s.Route_Day,
>>>		s.Route_Number,
>>>		s.Municipality,
>>>		s.Upload_Id,
>>>		s.Spot_Latitude,
>>>		s.Spot_Longitude,
>>>		s.Spot_Heading,
>>>		s.Spot_Speed,
>>>		s.Spot_Altitude,
>>>		s.Spot_Time,
>>>		s.Spot_Status,
>>>		s.Sentinel,
>>>		s.Record_Status,
>>>		s.Record_Status_dt
>>>	FROM TrackSpot s, TruckAccess t
>>>	WHERE s.TruckID = t.TruckID
>>>		AND s.CompanyID = @CompanyID
>>>		AND Spot_Time >= @StartRange
>>>		AND Spot_Time <= @EndRange
>>>		AND Sentinel = @Sentinel
>>>
>>>END
>>>GO
>>>
>>>
>>>I want to set the following fields that are included in this selection.
>>>s.SentinelMark = @SentinelMark
>>>s.Record_Status_dt = DateTime.Now.ToUniversalTime
>>>s.Record_Status = "Sentinel Marked"
>>
>>You want to update these fields?
>>If you do, that you should fire the different UPDATE statement with the same tables and WHERE clause:
>>
>>
>>CREATE PROCEDURE dbo.GetSpotsByCompanyIDWithRange
>>(
>>	@CompanyID UniqueIdentifier,
>>	@StartRange DateTime,
>>	@EndRange DateTime,
>>	@Sentinel Bit,
>>	@SentinelMark VarChar
>>) 
>>AS
>>BEGIN
>>	SET NOCOUNT ON;
>>
>>	SELECT  s.Track_Id,
>>		s.CompanyID,
>>		s.TruckID,
>>		t.TruckCode,
>>		s.DriverID,
>>		s.Truck_Ip,
>>		s.IsTip,
>>		s.Spot_Message,
>>		s.Route_Day,
>>		s.Route_Number,
>>		s.Municipality,
>>		s.Upload_Id,
>>		s.Spot_Latitude,
>>		s.Spot_Longitude,
>>		s.Spot_Heading,
>>		s.Spot_Speed,
>>		s.Spot_Altitude,
>>		s.Spot_Time,
>>		s.Spot_Status,
>>		s.Sentinel,
>>		s.Record_Status,
>>		s.Record_Status_dt
>>	FROM TrackSpot s, TruckAccess t
>>	WHERE s.TruckID = t.TruckID
>>		AND s.CompanyID = @CompanyID
>>		AND Spot_Time >= @StartRange
>>		AND Spot_Time <= @EndRange
>>		AND Sentinel = @Sentinel
>>
>>    UPDATE ........
>>	FROM TrackSpot s
>>        INNER JOIN TruckAccess t ON s.TruckID = t.TruckID
>>	WHERE s.CompanyID = @CompanyID
>>	     AND Spot_Time >= @StartRange
>>	     AND Spot_Time <= @EndRange
>>	     AND Sentinel = @Sentinel
>>END
>>
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform