Showing posts with label distinct. Show all posts
Showing posts with label distinct. Show all posts

Friday, February 24, 2012

About SQL Query

Hi Friends,

I have one Query

select Name from Test1 where ID in (Select ID from (
if ('a' = 'a')
begin
Select DISTINCT ID,Name from Test2
End
) xxx )

and i want the query in same format....but when i execute this it will give an error

Server: Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'If'.
Server: Msg 170, Level 15, State 1, Line 26
Line 26: Incorrect syntax near ')'.

And if drop or remove if, begin ,end functionl;ity then it working fine....

Anyone help me solve this...

ASAP

AshutoshThere is no IF available in Transact-SQL. In general, the replacement for "IF" would be "CASE". But simply using CASE in the statement you provided will not work.

Maybe you could explain what it is you are trying to do, along with data examples...

Terri|||Hi Friend,

Actually i have a only query

if ('a' = 'a')
begin
Select DISTINCT ID,Name from Test2
End

Like this and that query

select Name from Test1 where ID in (Select ID from (
if ('a' = 'a')
begin
Select DISTINCT ID,Name from Test2
End
) xxx )

is generated automatically so error came there that query is not proper i can chage only my query and not the above ...so if any possibility to change that query above one only with if and begin then that problem will solve.....else tell me the other way.....i can change only this query it has 3 if statement so.......

select Name from Test1 where ID in (Select ID from (
if ('a' = 'a')
begin
Select DISTINCT ID,Name from Test2
End
) xxx )

might be u clear what i want now...still if not then i can explan u well

Ashutosh|||> There is no IF available in Transact-SQL.

errr... yes there is, though I agree not in the context you're thinking of. check Books Online.|||Hi Friends,

so how can i solve this problem? no way to solve this??

Ashutosh|||Sorry - I should have been clearer. IF is only available as a flow control command, not within a query.

Ashutosh -- I am still not clear. What is the purpose of the "xxx"? Could you please provide data examples to show the data you have and the result you are looking for?

Terri|||> so how can i solve this problem?

IF should be used so

IFsome criteria
BEGIN
sql statements here
END
ELSE
BEGIN
some other SQL statements here
END

GO

not in the middle of the statement as you've tried to use it. it should enclose complete SQL statements. Check the docs!

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!
>

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!
>

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!
>