显示标签为“range”的博文。显示所有博文
显示标签为“range”的博文。显示所有博文

2012年3月27日星期二

Float and Bigint

In SQL 2005, the Float has storage size 4 or 8 bytes, how does it has
range -2.23E308 to 2.23E308?
For BigInt, it has 8 bytes but has range -2E63 to 2E63-1?> In SQL 2005, the Float has storage size 4 or 8 bytes, how does it has
> range -2.23E308 to 2.23E308?
Float follows the IEEE 754 specification regarding approximate numeric
types. A wide range of values can be stored but not all decimal values
within the range can be exactly represented.
> For BigInt, it has 8 bytes but has range -2E63 to 2E63-1?
No, the bigint range from the Books Online is:
Integer (whole number) data from -2^63 (-9,223,372,036,854,775,808)
through 2^63-1 (9,223,372,036,854,775,807).
Hope this helps.
Dan Guzman
SQL Server MVP
"Alan T" <alanNOSPAMpltse@.yahoo.com.au> wrote in message
news:eK6eafT6HHA.484@.TK2MSFTNGP06.phx.gbl...
> In SQL 2005, the Float has storage size 4 or 8 bytes, how does it has
> range -2.23E308 to 2.23E308?
> For BigInt, it has 8 bytes but has range -2E63 to 2E63-1?
>

2012年3月19日星期一

Fixing a screwup

After synching a handful of subscribers, I reviewed the data that came back
and realized I forgot to set auto range identity on two tables that required
it. So I dumped the pub, dumped the subscriptions, manually assigned the
identity values to consecutive identities, reset the identity columns to
"not for replication", re-created the publication, then let the subscribers
resynch.
Before anyone goes berserk on manually assigning an identity value, note
that at this time, the identity values on those two tables (at the "end of
the food chain" so to speak) are not being used or keyed to other tables,
but may in the future. Whether a record is 1 or 15 or whatever is
irrelevant, but I want to simply ensure uniqueness for future use.
So, my question is, have I overlooked anything or are there other hidden
potential issues?
Earl,
I'm not too sure what you did. It seems as though you set up a nosync
initialization? Or was it a normal initialization but without automatic
range management?
In one place I worked they would often forget to set the automatic range
management on articles. Rather than reinitializing, which was simply not
possible, what they'd do is reseed the identity value at the subscriber.
There were only 3 subscribers, so there was never a posibility of range
overlaps. The main difference to automatic range management was the absence
of check constraints and no possibility of getting a new range from
MSrepl_identity_range but as the difference between seeds was so large it
would be 200 years or so before a clash occurs.
Rgds,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||Paul, it was a normal initialization but without automatic range management.
It's an easy thing to forget, especially if you've had to go through a lot
of contortions massaging the data into shape. The subscribers are PocketPCs,
so it would've been a real PIA to reseed those values. The identity values
back in the pub (once synched) were like this:
1
2
3
...
1
2
3
...
1
2
3
Seemed easier to drop the pub and the subscriptions, then do a manual reseed
of the pub tables (had I not caught it immediately and thus been dealing
with a large number of records, I'm not sure how I would've handled the
situation):
1
2
3
4
5
6
7
8
9
...
Which brings to mind a followup question: If my subscribers had the same
name as their pubs then I could've just created a new publication AND
subscription and just moved on? Thanks for your thoughts!
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:e04BD$vdFHA.892@.tk2msftngp13.phx.gbl...
> Earl,
> I'm not too sure what you did. It seems as though you set up a nosync
> initialization? Or was it a normal initialization but without automatic
> range management?
> In one place I worked they would often forget to set the automatic range
> management on articles. Rather than reinitializing, which was simply not
> possible, what they'd do is reseed the identity value at the subscriber.
> There were only 3 subscribers, so there was never a posibility of range
> overlaps. The main difference to automatic range management was the
> absence of check constraints and no possibility of getting a new range
> from MSrepl_identity_range but as the difference between seeds was so
> large it would be 200 years or so before a clash occurs.
> Rgds,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>
|||Earl,
"Which brings to mind a followup question: If my subscribers had the same
name as their pubs then I could've just created a new publication AND
subscription and just moved on? Thanks for your thoughts!"
- sorry - I'm probably being a bit thick, but I don't follow this. How can
the subscriber have the same computer name as the publisher, and in what way
would this simplify things?
Rgds,
Paul Ibison (www.replicationanswers.com)
|||Hehe ... merge publication on a PocketPC, subscribers assign their own
subscription name, which I usually just keep as the same name across the
board. I have an input form in my app where the users can enter all of their
replication settings. In this case, once I had reseeded the tables, I
could've just created a new pub and set up auto range management at the same
time. Instead of the users synching to the old pub, they would enter the new
pub and subscription names, tap the synch button (which would create a new
db onboard and download the new pub) and keep on trucking. Perhaps it is me
that is "thick" on this one because that may or may not have worked (maybe
I'll try that next time).
Sorry for not including more about how my app works -- I'm primarily a
developer and not a DBA (although since I spend so much time with SLQ
Server, I decided long ago to go ahead and try to get the MCDBA cert).
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:ehq9zp0dFHA.2212@.TK2MSFTNGP14.phx.gbl...
> Earl,
> "Which brings to mind a followup question: If my subscribers had the same
> name as their pubs then I could've just created a new publication AND
> subscription and just moved on? Thanks for your thoughts!"
> - sorry - I'm probably being a bit thick, but I don't follow this. How can
> the subscriber have the same computer name as the publisher, and in what
> way would this simplify things?
> Rgds,
> Paul Ibison (www.replicationanswers.com)
>

2012年3月7日星期三

Fiscal Month Date Range: 22 thru 21

I'm looking for a script to do the following?
I need to have a date range for each month of the year from the 22nd of each
month to the 21st of the next.
This doesn't work... as it starts at the first, I need it to start at the 22
of
the previous month.
declare @.date datetime
set @.date = '1/1/2005'
select case when datepart(mm,@.date) = 1 and datepart(dd,@.date) between 1 and
21
then 1 else 0 end
TIA
JeffP...Considered a calendar table to mark fiscal months?
http://www.aspfaq.com/2519
"JDP@.Work" <JPGMTNoSpam@.sbcglobal.net> wrote in message
news:ewMNyExBGHA.1288@.TK2MSFTNGP09.phx.gbl...
> I'm looking for a script to do the following?
> I need to have a date range for each month of the year from the 22nd of
> each
> month to the 21st of the next.
> This doesn't work... as it starts at the first, I need it to start at the
> 22 of
> the previous month.
> declare @.date datetime
> set @.date = '1/1/2005'
> select case when datepart(mm,@.date) = 1 and datepart(dd,@.date) between 1
> and 21
> then 1 else 0 end
>
> TIA
> JeffP...
>|||The calendar table is an excellent solution. If you do not want to do
that, you could use a Case statement for your solution. This example
assumes your fiscal year starts on December 22.
select <all other columns>,
case when datepart(day,datefield) <= 21
then cast(year(datefield) as varchar(4)) + ' ' + right('0' +
cast(month(datefield) as varchar(2)),2)
when datepart(day,datefield > 21 and month(datefield) = 12 then
cast(year(datefield) + 1 as varchar(4)) + ' 01'
else cast(year(datefield) as varchar(4)) + ' ' + right('0' +
cast(month(datefield) + 1 as varchar(2)),2)
else date(mm,datefield) + 1 end)
as FiscalMonth|||Oops - don't forget the END to the Case statement ;-)|||All, Thanks...
Thanks, one the one hand the case stmt works well for a quick & dirty query,
but
I'm like'ing the table, that way if anything changes in the rules I can crea
te
an interfact to the cal table and make adjustments.
TIA
JeffP....
"Gary Gibbs" <ggibbs@.aahs.org> wrote in message
news:1135271277.811769.38450@.g49g2000cwa.googlegroups.com...
> Oops - don't forget the END to the Case statement ;-)
>|||Here is another way. Probably a bit faster then using table lookups if you
call it a lot.
declare @.mthStart datetime
declare @.mthEnd datetime
declare @.i int
set @.mthStart = '1/22/2005'
set @.mthEnd = dateadd(day, 30, @.mthStart)
set @.i = 1;
while (@.i <= 12)
begin
select @.mthStart, @.mthEnd
set @.mthStart = dateadd(month, 1, @.mthStart)
set @.mthEnd = dateadd(month, 1, @.mthEnd)
set @.i = @.i + 1
end
William Stacey [MVP]
"JDP@.Work" <JPGMTNoSpam@.sbcglobal.net> wrote in message
news:%23bXcyTyBGHA.3984@.TK2MSFTNGP14.phx.gbl...
> All, Thanks...
> Thanks, one the one hand the case stmt works well for a quick & dirty
> query, but
> I'm like'ing the table, that way if anything changes in the rules I can
> create
> an interfact to the cal table and make adjustments.
> TIA
> JeffP....
> "Gary Gibbs" <ggibbs@.aahs.org> wrote in message
> news:1135271277.811769.38450@.g49g2000cwa.googlegroups.com...
>|||Thanks to all who posted...
This is nearly perfect... All the links were helpful as I have other client
s
with different date range issues.
create table #view_paid (datepaid varchar(10) ,polchoice varchar(2))
insert #view_paid
select '01/03/2005' ,10
insert #view_paid
select '01/13/2005' ,10
insert #view_paid
select '01/23/2005' ,10
insert #view_paid
select '01/31/2005' ,10
insert #view_paid
select '02/03/2005' ,10
insert #view_paid
select '02/13/2005' ,10
insert #view_paid
select '02/23/2005' ,10
declare @.mthStart datetime ,@.mthEnd datetime
set @.mthStart = '1/22/2005'
set @.mthEnd = dateadd(day, 30, @.mthStart)
select datepaid ,polchoice
,dateadd(ms,-3,dateadd(mm,datediff(mm,0,dateadd(mm,-1,datepaid)),0)+22)
Period_Start
,dateadd(mm,datediff(mm,0,datepaid),0)+2
1 Period_End
,Jan = case when datepaid between dateadd(mm,-1,@.mthStart) and
dateadd(mm,-1,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end
,Feb = case when datepaid between dateadd(mm,0,@.mthStart) and
dateadd(mm,0,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end
,Mar = case when datepaid between dateadd(mm,1,@.mthStart) and
dateadd(mm,1,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end
from #view_paid with(nolock)
where cast(datepaid as datetime) between '01/01/2005' and '03/27/2005'
order by datepaid
select [Year] = datepart(yy,datepaid)
,JanTotals =sum( case when datepaid between dateadd(mm,-1,@.mthStart) and
dateadd(mm,-1,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end)
,FebTotals = sum(case when datepaid between dateadd(mm,0,@.mthStart) and
dateadd(mm,0,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end)
,MarTotals = sum(case when datepaid between dateadd(mm,1,@.mthStart) and
dateadd(mm,1,@.mthEnd) and (cast(PolChoice as varchar(1)) = 1) then 1 else 0
end)
from #view_paid with(nolock)
where cast(datepaid as datetime) between '01/01/2005' and '03/27/2005'
group by datepart(yy,datepaid)
drop table #view_paid
JeffP....
"William Stacey [MVP]" <william.stacey@.gmail.com> wrote in message
news:ud17lO0BGHA.3600@.TK2MSFTNGP10.phx.gbl...
> Here is another way. Probably a bit faster then using table lookups if yo
u
> call it a lot.
> declare @.mthStart datetime
> declare @.mthEnd datetime
> declare @.i int
> set @.mthStart = '1/22/2005'
> set @.mthEnd = dateadd(day, 30, @.mthStart)
> set @.i = 1;
> while (@.i <= 12)
> begin
> select @.mthStart, @.mthEnd
> set @.mthStart = dateadd(month, 1, @.mthStart)
> set @.mthEnd = dateadd(month, 1, @.mthEnd)
> set @.i = @.i + 1
> end
> --
> William Stacey [MVP]
> "JDP@.Work" <JPGMTNoSpam@.sbcglobal.net> wrote in message
> news:%23bXcyTyBGHA.3984@.TK2MSFTNGP14.phx.gbl...
>

2012年2月24日星期五

firing a trigger on someone's birthday

Hi,
Could somebody help me create a trigger which should be executed when
someone's birthday in months fall in range, like between 18 months and
36 months.
If one falls in that range, the trigger should set a value for that
person to 1.I don't see how or why a trigger would be appropriate for this. Put the
birthdate in your table (and the created / updated date if that's
important) then put the range indicator in a view. You can use the
DATEDIFF function to calculate it:
CASE WHEN
DATEDIFF(MONTH, birthdate, CURRENT_TIMESTAMP)
BETWEEN -18 AND 18
THEN 1 ELSE 0
END
(or use created_date in place of CURRENT_TIMESTAMP if that was what you
meant.)
David Portas
SQL Server MVP
--|||dportas@.gmail.com wrote:
> I don't see how or why a trigger would be appropriate for this. Put the
> birthdate in your table (and the created / updated date if that's
> important) then put the range indicator in a view. You can use the
> DATEDIFF function to calculate it:
> CASE WHEN
> DATEDIFF(MONTH, birthdate, CURRENT_TIMESTAMP)
> BETWEEN -18 AND 18
> THEN 1 ELSE 0
> END
> (or use created_date in place of CURRENT_TIMESTAMP if that was what you
> meant.)
>
Hello David,
The thing is, that the value that should be set to 1 or 0 is in another
table.
I have a view which calculates one age in months. When getting the data
i split up the data in ranges uses a where clause. So i have different
recordsets of subjects where the ages are between 18 and 36, 36 and 52,
etc. What i'm trying to do is when a subject falls in the second range,
like 36 and 52 because he's getting older, i want to set a value in
another table to 1.
I hope i'm making any sense|||Hi Jason !
As the age of people hardly change during the day ;-) a trigger would
be IMHO the wrong solution. Setup a daily / nightly job which updates
the values of the table rather than doing this with a trigger. If the
nightly job is too seldom for you you can schedule the job to run more
often.
HTH, jens Suessmeyer.