 |
|
 |
|
Next: Permissions for new account
|
| Author |
Message |
External

Since: Dec 20, 2009 Posts: 1
|
(Msg. 1) Posted: Sun Dec 20, 2009 5:25 am
Post subject: loop between 2 datetime field values Archived from groups: microsoft>public>sqlserver>programming (more info?)
|
|
|
Hi how can i loop between 2 datetime value ex:
i have this stored procedure:
@onde CHAR(100) = NULL,
@quandoinicio CHAR(100) = NULL,
@quandofim CHAR(100) = NULL,
@quantominimo CHAR(100) = NULL,
@quantomaximo CHAR(100) = NULL,
@quartos CHAR(100) = NULL,
@pessoas CHAR(100) = NULL,
@tipo CHAR(100) = NULL,
@rcama CHAR(100) = NULL,
@rbanho CHAR(100) = NULL,
@limpeza CHAR(100) = NULL,
@maqloica CHAR(100) = NULL,
@maqroupa CHAR(100) = NULL,
@arcon CHAR(100) = NULL,
@satcabo CHAR(100) = NULL,
@internet CHAR(100) = NULL,
@barbecue CHAR(100) = NULL,
@formpesqavancadabut CHAR(100) = NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT distinct
cod_casa,destino,data_activo,tipo,pessoas,localidade,img_1,img_2 ,img_3,
img_4,data_act, certif,valor_voto,n_voto
FROM
pesq_1_com_feedback
WHERE
((@onde IS NULL) OR (localidade = @onde))
AND ((@quandoinicio IS NULL) OR (inicio >= @quandoinicio))
AND ((@quandofim IS NULL) OR (fim <= @quandofim))
AND ((@quantominimo IS NULL) OR (preco > @quantominimo ))
AND ((@quantomaximo IS NULL) OR (preco < @quantomaximo ))
AND ((@quartos IS NULL) OR (quartos = @quartos ))
AND ((@pessoas IS NULL) OR (pessoas = @pessoas ))
AND ((@tipo IS NULL) OR (tipo = @tipo ))
AND ((@rcama IS NULL) OR (roupascama = @rcama ))
AND ((@rbanho IS NULL) OR (roupasbanho = @rbanho ))
AND ((@limpeza IS NULL) OR (limpeza = @limpeza ))
AND ((@maqloica IS NULL) OR (mlavaloica = @maqloica ))
AND ((@maqroupa IS NULL) OR (mlavaroupa = @maqroupa ))
AND ((@arcon IS NULL) OR (ar_condicionado = @arcon))
AND ((@satcabo IS NULL) OR (satcabo = @satcabo))
AND ((@internet IS NULL) OR (internet = @internet))
AND ((@barbecue IS NULL) OR (barbecue = @barbecue))
i have availibility calendar that have rows with
startdate and end date:
select startdate,enddate where cod_casa="record from the first select"
and livre=0
it is possible to loop between startdate to enddate?
as i do do while not rs2.eof
for k = cdate(rs2("startdate")) to cdate(rs2("enddate"))
i'm not experienced, but this loops in asp become slow and i think
treres a way to do it in sql server >> Stay informed about: loop between 2 datetime field values |
|
| Back to top |
|
 |  |
External

Since: Aug 24, 2003 Posts: 1744
|
(Msg. 2) Posted: Sun Dec 20, 2009 5:25 am
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
led
It is not clear what you are trying to achive, I mean, why loop? Can you
post sample data to be tested?
"led" wrote in message
> Hi how can i loop between 2 datetime value ex:
>
>
> i have this stored procedure:
>
> @onde CHAR(100) = NULL,
> @quandoinicio CHAR(100) = NULL,
> @quandofim CHAR(100) = NULL,
> @quantominimo CHAR(100) = NULL,
> @quantomaximo CHAR(100) = NULL,
> @quartos CHAR(100) = NULL,
> @pessoas CHAR(100) = NULL,
> @tipo CHAR(100) = NULL,
> @rcama CHAR(100) = NULL,
> @rbanho CHAR(100) = NULL,
> @limpeza CHAR(100) = NULL,
> @maqloica CHAR(100) = NULL,
> @maqroupa CHAR(100) = NULL,
> @arcon CHAR(100) = NULL,
> @satcabo CHAR(100) = NULL,
> @internet CHAR(100) = NULL,
> @barbecue CHAR(100) = NULL,
> @formpesqavancadabut CHAR(100) = NULL
> AS
> BEGIN
> SET NOCOUNT ON;
>
> SELECT distinct
> cod_casa,destino,data_activo,tipo,pessoas,localidade,img_1,img_2 ,img_3,
> img_4,data_act, certif,valor_voto,n_voto
>
> FROM
> pesq_1_com_feedback
> WHERE
> ((@onde IS NULL) OR (localidade = @onde))
> AND ((@quandoinicio IS NULL) OR (inicio >= @quandoinicio))
> AND ((@quandofim IS NULL) OR (fim <= @quandofim))
> AND ((@quantominimo IS NULL) OR (preco > @quantominimo ))
> AND ((@quantomaximo IS NULL) OR (preco < @quantomaximo ))
> AND ((@quartos IS NULL) OR (quartos = @quartos ))
> AND ((@pessoas IS NULL) OR (pessoas = @pessoas ))
> AND ((@tipo IS NULL) OR (tipo = @tipo ))
> AND ((@rcama IS NULL) OR (roupascama = @rcama ))
>
> AND ((@rbanho IS NULL) OR (roupasbanho = @rbanho ))
> AND ((@limpeza IS NULL) OR (limpeza = @limpeza ))
> AND ((@maqloica IS NULL) OR (mlavaloica = @maqloica ))
> AND ((@maqroupa IS NULL) OR (mlavaroupa = @maqroupa ))
> AND ((@arcon IS NULL) OR (ar_condicionado = @arcon))
> AND ((@satcabo IS NULL) OR (satcabo = @satcabo))
> AND ((@internet IS NULL) OR (internet = @internet))
> AND ((@barbecue IS NULL) OR (barbecue = @barbecue))
>
> i have availibility calendar that have rows with
> startdate and end date:
>
> select startdate,enddate where cod_casa="record from the first select" and
> livre=0
>
> it is possible to loop between startdate to enddate?
>
> as i do do while not rs2.eof
> for k = cdate(rs2("startdate")) to cdate(rs2("enddate"))
>
> i'm not experienced, but this loops in asp become slow and i think treres
> a way to do it in sql server
> >> Stay informed about: loop between 2 datetime field values |
|
| Back to top |
|
 |  |
External

Since: May 30, 2004 Posts: 2061
|
(Msg. 3) Posted: Sun Dec 20, 2009 7:25 am
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jan 11, 2008 Posts: 1089
|
(Msg. 4) Posted: Mon Dec 21, 2009 4:59 pm
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jan 11, 2008 Posts: 579
|
(Msg. 5) Posted: Mon Dec 21, 2009 10:18 pm
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jan 10, 2008 Posts: 213
|
(Msg. 6) Posted: Tue Dec 22, 2009 4:25 am
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
--CLEKO--
You appear to be posting on the wrong forum.
SQL Server does have loops, it does have sequential access, it has xml, it
has unstructured search, it has mdx, it has dmx, it has .... well, a ton of
other stuff.
If you don't know anything about SQL Server (remember - this forum is for
users of SQL Server) then check out books online which can be easily found
on the internet.
--ROGGIE--
"--CELKO--" wrote in message
> SQL has no loops. SQL has no sequential data access. It is a
> declarative language that works with completed sets of rows, not
> records from sequential files.
>
> If you don't know anything about RDBMS, then get a copy of the
> simplest intro book I know --
> http://www.amazon.com/Manga-Guide-Databases-Mana-Takahashi/dp/1593271905
>
>
> >> Stay informed about: loop between 2 datetime field values |
|
| Back to top |
|
 |  |
External

Since: May 30, 2004 Posts: 2061
|
(Msg. 7) Posted: Tue Dec 22, 2009 6:25 pm
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jan 10, 2008 Posts: 213
|
(Msg. 8) Posted: Wed Dec 23, 2009 2:26 am
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
The --CLEKO-- troll is getting more and more extreme and off topic for this
Microsoft SQL Server forum.
Must be his age now Erland.
But this is getting very serious now; its confusing the hell out of people
just wanting to use what is in the product and don't care about portability.
Tony.
"Erland Sommarskog" wrote in message
> --CELKO-- (jcelko212@earthlink.net) writes:
>> SQL has no loops. SQL has no sequential data access. It is a
>> declarative language that works with completed sets of rows, not
>> records from sequential files.
>
>
> The other day you said:
>
>> There is a WHILE loop in T-SQL last time I looked. Does the T-SQL
>> compiler remove invariant expressions in the WHILE loop? Does the T-SQL
>> compiler unroll a WHILE loop (granted that is easier with a counting
>> loop)?
>
> While there are no loops in SQL, you still care about whether SQL Server
> unrolls them!
>
>
> --
> Erland Sommarskog, SQL Server MVP, esquel.TakeThisOut@sommarskog.se
>
> Links for SQL Server Books Online:
> SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
> SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
> SQL 2000:
> http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
> >> Stay informed about: loop between 2 datetime field values |
|
| Back to top |
|
 |  |
External

Since: Jan 11, 2008 Posts: 1089
|
(Msg. 9) Posted: Wed Dec 23, 2009 12:35 pm
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
I did not know that SQL = T-SQL  I did not know that cursors are
the preferred way to code and that you want to avoid declarative
code.
You knew exactly what I was saying. Come on, I expect this kind of
stupid sniping from Tony. You are usually better. >> Stay informed about: loop between 2 datetime field values |
|
| Back to top |
|
 |  |
External

Since: Jan 10, 2008 Posts: 213
|
(Msg. 10) Posted: Wed Dec 23, 2009 5:25 pm
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
> You knew exactly what I was saying. Come on, I expect this kind of
> stupid sniping from Tony. You are usually better.
>
I "snipe"
You "troll"
We are as bad as each other
Perhaps you might want to consider this is a MICROSOFT SQL SERVER forum, not
a general "SQL" forum; there is a forum for that somewhere else - it gets
about 10 posts per month!
--ROGGIE--
"--CELKO--" wrote in message
> I did not know that SQL = T-SQL I did not know that cursors are
> the preferred way to code and that you want to avoid declarative
> code.
>
> You knew exactly what I was saying. Come on, I expect this kind of
> stupid sniping from Tony. You are usually better.
> >> Stay informed about: loop between 2 datetime field values |
|
| Back to top |
|
 |  |
External

Since: May 30, 2004 Posts: 2061
|
(Msg. 11) Posted: Wed Dec 23, 2009 6:25 pm
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Sep 30, 2008 Posts: 44
|
(Msg. 12) Posted: Wed Dec 23, 2009 8:25 pm
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
On 22-Dec-2009, "Tony Rogerson" wrote:
> The --CLEKO-- troll is getting more and more extreme and off topic for
> this
> Microsoft SQL Server forum.
>
> Must be his age now Erland.
>
> But this is getting very serious now; its confusing the hell out of people
>
> just wanting to use what is in the product and don't care about
> portability.
As I remember he was pretty intolerable around this time of year last
year...more so than usual. I do worry about his liver.... >> Stay informed about: loop between 2 datetime field values |
|
| Back to top |
|
 |  |
External

Since: Jan 11, 2008 Posts: 1089
|
(Msg. 13) Posted: Wed Dec 23, 2009 9:46 pm
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
>> But this is getting very serious now; its confusing the hell out of people just wanting to use what is in the product and don't care about portability. <<
A programmer would have be in a very small isolated environment to
deal with one and only one SQL product. DB2 and Oracle are the big
two; MySQL and LAMP rules the web; Teradata dominates data
warehousing; some really good SQLs have niches. Tony, you will not
fall off the edge of the World when you leave your village.
Like most Cowboy Coders, you think that portability is only across SQL
products; it is across releases of the same product. The Pros that
wrote to Standards were not screwed changes that brought SQL Server in
that direction.
If you want to have a specialization in a dialect, that is fine. Good
tool. I use my math for BI. But a cowboy will try to lock his client
into dialect for HIS job security and not the long-term good of the
client. A professional SQL programmer ought to know the difference and
be able to justify and document his choices when he picks dialect over
standards.
Much of my work is to make SQL portable. I work for companies that
need to run on multiple hardware and software platforms. They are
growing. Your work seems to be keeping your clients away from the
version of SQL Server the you know.
The professional also ought to have a theoretical model (what I call a
mindset) so he has a higher abstraction of the problems and the
solutions. >> Stay informed about: loop between 2 datetime field values |
|
| Back to top |
|
 |  |
External

Since: Jan 10, 2008 Posts: 213
|
(Msg. 14) Posted: Thu Dec 24, 2009 1:25 am
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Ok then - put a disclaimer at the bottom of all your posts that it relates
entirely to the ISO SQL standard and remember to note which incarnation of
it - ANSI 89, 92, 2003 etc
Perhaps then you'll stop posting drivel that doesn't even work on this
product like YYYY-MM-DD, like the way the internals of this product work
(one pass compile etc..) etc....
Don't worry --CKELO-- I've got 5 years DB2, ok - 3 months Oracle, and I'll
be learning Teradata on the masters degree in BI that I'm starting in
January - hardly a one trick pony!
I'm fully aware of what's what give my 23+ experience within IT, at the coal
face rather than in some 4 walled classroom turning hearsay into fact.
Portability died a long time ago - its not that often you come across
anybody who cares about it, heard of it and much less actually doing a
project with that as a deliverable - remember, I'm working day in, day out
with multiple clients and also have my source from the user group I run - a
user group of a good few thousand people here in the UK - so I know what is
what; but do you? I suspect not; but you'll only know that yourself  .
--ROGGIE--
"--CELKO--" wrote in message
>>> But this is getting very serious now; its confusing the hell out of
>>> people just wanting to use what is in the product and don't care about
>>> portability. <<
>
> A programmer would have be in a very small isolated environment to
> deal with one and only one SQL product. DB2 and Oracle are the big
> two; MySQL and LAMP rules the web; Teradata dominates data
> warehousing; some really good SQLs have niches. Tony, you will not
> fall off the edge of the World when you leave your village.
>
> Like most Cowboy Coders, you think that portability is only across SQL
> products; it is across releases of the same product. The Pros that
> wrote to Standards were not screwed changes that brought SQL Server in
> that direction.
>
> If you want to have a specialization in a dialect, that is fine. Good
> tool. I use my math for BI. But a cowboy will try to lock his client
> into dialect for HIS job security and not the long-term good of the
> client. A professional SQL programmer ought to know the difference and
> be able to justify and document his choices when he picks dialect over
> standards.
>
> Much of my work is to make SQL portable. I work for companies that
> need to run on multiple hardware and software platforms. They are
> growing. Your work seems to be keeping your clients away from the
> version of SQL Server the you know.
>
> The professional also ought to have a theoretical model (what I call a
> mindset) so he has a higher abstraction of the problems and the
> solutions.
> >> Stay informed about: loop between 2 datetime field values |
|
| Back to top |
|
 |  |
External

Since: Jan 11, 2008 Posts: 579
|
(Msg. 15) Posted: Thu Dec 24, 2009 10:13 am
Post subject: Re: loop between 2 datetime field values [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
No, you did not say that cursors are not the preferred way. You said "SQL
has no loops. SQL has no sequential data access."
That is a patently wrong statement whether we are talking TSQL or your
beloved ANSI SQL.
--
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net
"--CELKO--" wrote in message
>I did not know that SQL = T-SQL I did not know that cursors are
> the preferred way to code and that you want to avoid declarative
> code.
>
> You knew exactly what I was saying. Come on, I expect this kind of
> stupid sniping from Tony. You are usually better.
> >> Stay informed about: loop between 2 datetime field values |
|
| Back to top |
|
 |  |
| Related Topics: | Get milliseconds from datetime field -
auto update of datetime field - I need to create a datetime field that gets automatically updated with the current datetime whenever the record is modified. I assume this would be accomplished with a trigger, right? But the one I wrote doesn't seem to do anything. Any suggestions?
Can't select a datetime field in a query without time port.. - Hi, I am doing some project with SQL Server 2000 and C#. I am using a SELECT statement to get a column and to bind it to a dropdown list. The column is a datetime format. I don't need time portion of it. Before I tried any CONVERT functions my query..
Query design help - view the remaining time in a datetime .. - Hi need some help with a query/table I want to design. My database stores records that give the users a list of time-slots available for an activity. The user is allowed to chose which slot, or part slot, they want to carry out the activity. Table A...
Conversion of xs:datetime to SQL server 2005 datetime - Folks, I someone you can help me here! I'm using T-SQL to process an XML document containing dates appended with timezone information (xsd:datetime) and am hitting errors when I try to extract these vlaues into SQL server datetime variables. I can.. |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|