Showing posts with label syntax. Show all posts
Showing posts with label syntax. Show all posts

Thursday, March 8, 2012

ABS () and dates

What would the Sql syntax look like if I wanted to select +/- 10 days of a d
elivery date.
For instance; Table has Actual Delivery Date & Expected Delivery date, and u
sing the ABS Sql function, I want to select only the rows from the table tha
t were delivered with +/- 10 days.
And even if it's not the best way to do it, I would really like the info on
ABS.
Any ideas?
Thanx!Use DATEADD function like:
BETWEEN DATEADD ( d, -10, dt ) AND DATEADD ( d, 10, dt )
Anith|||I don't know your table structure or sample data, but here's a guess:
WHERE ABS(DATEDIFF(DAY, ActualDate, ExpectedDate)) <= 10
"Jude" <judes@.email.uophx.edu> wrote in message
news:%23NQBlSwQGHA.1868@.TK2MSFTNGP09.phx.gbl...
What would the Sql syntax look like if I wanted to select +/- 10 days of a
delivery date.
For instance; Table has Actual Delivery Date & Expected Delivery date, and
using the ABS Sql function, I want to select only the rows from the table
that were delivered with +/- 10 days.
And even if it's not the best way to do it, I would really like the info on
ABS.
Any ideas?
Thanx!|||Trust me I would, but someone taking a class asked me this question & I said
I had never used this function, but knew where to go to ask the experts!
Thanx!
"Anith Sen" <anith@.bizdatasolutions.com> wrote in message
news:u1RNgfwQGHA.4960@.TK2MSFTNGP12.phx.gbl...
> Use DATEADD function like:
> BETWEEN DATEADD ( d, -10, dt ) AND DATEADD ( d, 10, dt )
> --
> Anith
>|||Fantastic, Thanx so much Aaron! This is a favor for a friend who is taking
a class, and since I haven't used this function & would just use DateDiff
functions, I didn't have an answer. I knew the experts in here would
though!
Thanx again!!!!!
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:e%23zWkBxQGHA.1160@.TK2MSFTNGP09.phx.gbl...
>I don't know your table structure or sample data, but here's a guess:
> WHERE ABS(DATEDIFF(DAY, ActualDate, ExpectedDate)) <= 10
>
> "Jude" <judes@.email.uophx.edu> wrote in message
> news:%23NQBlSwQGHA.1868@.TK2MSFTNGP09.phx.gbl...
> What would the Sql syntax look like if I wanted to select +/- 10 days of a
> delivery date.
> For instance; Table has Actual Delivery Date & Expected Delivery date, and
> using the ABS Sql function, I want to select only the rows from the table
> that were delivered with +/- 10 days.
> And even if it's not the best way to do it, I would really like the info
> on ABS.
> Any ideas?
> Thanx!
>
>

Sunday, February 19, 2012

ABout SELECT Syntax?

Hi,everyone.

Today I met with a interesting problem. According to Microsoft SQL SERVER 2005 BOOKS ONLINE, there is following SELECT Syntax:

(1) SELECT @.local_variable (Transact-SQL)

For example:

DECLARE @.i int
SELECt @.i=100

(2) SELECt QUERY statement:

SELECT [ ALL | DISTINCT ]
[ TOP expression [ PERCENT ] [ WITH TIES ] ]
<select_list>
<select_list> ::=
....

For example,

[AdventureWorks]
SELECT * FROM DatabaseLog

To my surprise, in the given project, I met this kind of SELECT statement,

DECLARE @.w_type varchar(10), @.i varchar(30)
SELECT @.i='3'
SELECT @.w_type='OLTPNORMAL' WHERE @.i IN ('0','1','2','3','4','5','9',)
SELECT @.w_type

The result is:

OLTPNORMAL

However, I have not met with the kind of SELECT statement before. Please give me some advice. Thank you in advance.DECLARE @.w_type varchar(10), @.i varchar(30)
SELECT @.i='3'
SELECT @.w_type='OLTPNORMAL' WHERE @.i IN ('0','1','2','3','4','5','9')
SELECT @.w_type

The result is:

OLTPNORMAL

Thats absolutely okay,

SELECT @.i='3' -- assigning value '3' to @.i

SELECT @.w_type='OLTPNORMAL' WHERE @.i IN ('0','1','2','3','4','5','9') -- Assigning @.w_type='OLTPMORMAL' if where clause satisfies,here it is satisfying bcoz @.i='3'
SELECT @.w_type -displaying @.w_type|||Thank you,Rudra.

Here I have gotten the same result as yours. However, the kind of SQL Synax "SELECT...@.local_variable ...WHERE..." is not introduced in SQL SERVER 2005 in Microsoft SQL SERVER 2005 BOOKS ONLINE. So when I found this statement I felt surprised. Can you give me some advice to look for some introductions about the kind of SQL Synax ?

Thank you very much!|||Read this ...LINK (http://msdn2.microsoft.com/en-us/library/ms189484.aspx)
And please read the whole topic( you must scroll down) and then everything will be clear to you.

Thursday, February 16, 2012

about messges in microsoft sql express

:eek: :eek: :eek: :eek:
Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'contains'.
Msg 102, Level 15, State 1, Line 8
Incorrect syntax near ')'.

i am getting error messages like this.
I want to know what this message really
mean i.e list of messages corresponding to numbers......The SQL engine uses only the error numbers internally. Those are what the engine know about, and are how it complains about "bad code" that it receives from the SQL client. The error message displayed below the Msg line contains a description of the error in the current locale (in this case, essentially a human language like English, Spanish, French, etc).

The process of getting the text description is simply a table lookup, there's no "magic" associated with it. The table of error messages changes constantly, usually with every service pack.

-PatP|||they are stored in sysmessages:

select * from sysmessages where error in (102,156)

Thursday, February 9, 2012

About Count(Distinct) in AS

Hi,
Could Cube or MDX in Analysis Services execute "Count(Distinct)" or
"Sum(IIF())" Syntax?
If it could be, how could I open or write Count(Distinct) or Sum(IIF())
function or syntax in Cube?
As we know, MDX could execute Sum(IIF()), and how about Count(Distinct)?
Thanks!You can add an MDX expression in the cube definition, then the results of
the expression will be available as a cube cell, without re building the
cube...THis can be done in the cube editor of AS.
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"angi" <angi@.microsoft.com> wrote in message
news:uuY2g6nfEHA.2468@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Could Cube or MDX in Analysis Services execute "Count(Distinct)" or
> "Sum(IIF())" Syntax?
> If it could be, how could I open or write Count(Distinct) or Sum(IIF())
> function or syntax in Cube?
> As we know, MDX could execute Sum(IIF()), and how about Count(Distinct)?
> Thanks!
>