| Author |
Topic |
|
j0shua
Starting Member
40 Posts |
Posted - 2008-10-28 : 03:15:24
|
Hi, i have an sql statement. It works, however i find it long and tedious. Is there a better approach for this SQL statement? I am updating a table that has fixed rows. here is my sql statement. thank you.DECLARE @cbxJanuary As bitDECLARE @cbxFebruary As bitDECLARE @cbxMarch As bitDECLARE @cbxApril As bitDECLARE @cbxMay As bitDECLARE @cbxJune As bitDECLARE @cbxJuly As bitDECLARE @cbxAugust As bitDECLARE @cbxSeptember As bitDECLARE @cbxOctober As bitDECLARE @cbxNovember As bitDECLARE @cbxDecember As bitSET @cbxJanuary = 0SET @cbxFebruary = 0SET @cbxMarch = 0SET @cbxApril = 0SET @cbxMay = 0SET @cbxJune = 0UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxJanuaryWHERE fcMonth = 'January'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxFebruaryWHERE fcMonth = 'February'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxMarchWHERE fcMonth = 'March'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxAprilWHERE fcMonth = 'April'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxMayWHERE fcMonth = 'May'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxJuneWHERE fcMonth = 'June' |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-28 : 03:43:20
|
| [code]UPDATE dbo.tPeriodRestrictions SET fcOpen = 0WHERE fcMonth IN ( 'January','February','March','April','May','June')[/code] |
 |
|
|
j0shua
Starting Member
40 Posts |
Posted - 2008-10-28 : 03:58:34
|
quote: Originally posted by visakh16
UPDATE dbo.tPeriodRestrictions SET fcOpen = 0WHERE fcMonth IN ( 'January','February','March','April','May','June')
Thank you for the info, however, what if the parameters are user encoded? the status can be 1 or 0?like this one.quote: create procedure usp_PeriodRestrictionsasDECLARE @cbxJanuary As bitDECLARE @cbxFebruary As bitDECLARE @cbxMarch As bitDECLARE @cbxApril As bitDECLARE @cbxMay As bitDECLARE @cbxJune As bitDECLARE @cbxJuly As bitDECLARE @cbxAugust As bitDECLARE @cbxSeptember As bitDECLARE @cbxOctober As bitDECLARE @cbxNovember As bitDECLARE @cbxDecember As bitUPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxJanuaryWHERE fcMonth = 'January'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxFebruaryWHERE fcMonth = 'February'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxMarchWHERE fcMonth = 'March'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxAprilWHERE fcMonth = 'April'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxMayWHERE fcMonth = 'May'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxJuneWHERE fcMonth = 'June'......
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-28 : 04:01:39
|
| you meant @cbxJanuary to @cbxJune? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-28 : 04:07:15
|
it will be likeUPDATE dbo.tPeriodRestrictions SET fcOpen =CASE WHEN fcMonth ='January' THEN @cbxJanuary WHEN fcMonth ='February' THEN @cbxFebruary WHEN fcMonth ='March' THEN @cbxMarch .... WHEN fcMonth ='December' THEN @cbxDecember END WHERE fcMonth IN ( 'January','February','March','April','May','June'...,'December') |
 |
|
|
j0shua
Starting Member
40 Posts |
Posted - 2008-10-28 : 04:09:19
|
actually to december, i just posted a part of the whole statement.this goes something like this"create procedure usp_PeriodRestrictionsasDECLARE @cbxJanuary As bitDECLARE @cbxFebruary As bitDECLARE @cbxMarch As bitDECLARE @cbxApril As bitDECLARE @cbxMay As bitDECLARE @cbxJune As bitDECLARE @cbxJuly As bitDECLARE @cbxAugust As bitDECLARE @cbxSeptember As bitDECLARE @cbxOctober As bitDECLARE @cbxNovember As bitDECLARE @cbxDecember As bitUPDATE dbo.tPeriodRestrictionsSET fcOpen = @cbxJanuaryWHERE fcMonth = 'January'UPDATE dbo.tPeriodRestrictionsSET fcOpen = @cbxFebruaryWHERE fcMonth = 'February'UPDATE dbo.tPeriodRestrictionsSET fcOpen = @cbxMarchWHERE fcMonth = 'March'UPDATE dbo.tPeriodRestrictionsSET fcOpen = @cbxAprilWHERE fcMonth = 'April'UPDATE dbo.tPeriodRestrictionsSET fcOpen = @cbxMayWHERE fcMonth = 'May'UPDATE dbo.tPeriodRestrictionsSET fcOpen = @cbxJuneWHERE fcMonth = 'May'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxJuneWHERE fcMonth = 'June'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxJulyWHERE fcMonth = 'July'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxAugustWHERE fcMonth = 'August'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxSeptemberWHERE fcMonth = 'September'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxOctoberWHERE fcMonth = 'October'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxNovemberWHERE fcMonth = 'November'UPDATE dbo.tPeriodRestrictions SET fcOpen = @cbxDecemberWHERE fcMonth = 'December' |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-28 : 04:11:59
|
| [code]create procedure usp_PeriodRestrictionsasDECLARE @cbxJanuary As bitDECLARE @cbxFebruary As bitDECLARE @cbxMarch As bitDECLARE @cbxApril As bitDECLARE @cbxMay As bitDECLARE @cbxJune As bitDECLARE @cbxJuly As bitDECLARE @cbxAugust As bitDECLARE @cbxSeptember As bitDECLARE @cbxOctober As bitDECLARE @cbxNovember As bitDECLARE @cbxDecember As bitUPDATE dbo.tPeriodRestrictions SET fcOpen =CASE WHEN fcMonth ='January' THEN @cbxJanuary WHEN fcMonth ='February' THEN @cbxFebruary WHEN fcMonth ='March' THEN @cbxMarch .... WHEN fcMonth ='December' THEN @cbxDecember END WHERE fcMonth IN ( 'January','February','March','April','May','June'...,'December')[/code]not sure where you're setting values for bit variables though |
 |
|
|
j0shua
Starting Member
40 Posts |
Posted - 2008-10-28 : 04:35:34
|
ok i will try this one!! lots of thanksss!! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-28 : 04:37:39
|
quote: Originally posted by j0shua ok i will try this one!! lots of thanksss!! 
you're welcome |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-28 : 05:14:21
|
[code]UPDATE prSET pr.fcOpen = w.fcOpenFROM dbo.tPeriodRestrictions AS prINNER JOIN ( SELECT 'January' AS fcMonth, @cbxJanuary AS fcOpen UNION ALL SELECT 'February', @cbxFebruary UNION ALL SELECT 'March', @cbxMarch UNION ALL SELECT 'April', @cbxApril UNION ALL SELECT 'May', @cbxMay UNION ALL SELECT 'June', @cbxJune UNION ALL SELECT 'July', @cbxJuly UNION ALL SELECT 'August', @cbxAugust UNION ALL SELECT 'September', @cbxSeptember UNION ALL SELECT 'October', @cbxOctober UNION ALL SELECT 'November', @cbxJNovember UNION ALL SELECT 'December', @cbxDecember ) AS w ON w.fcMonth = pr.fcMonth[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
j0shua
Starting Member
40 Posts |
Posted - 2008-10-28 : 06:36:35
|
| Wow it works!!! This is so great information!!! GREAT THANKS! |
 |
|
|
|