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

Thursday, March 8, 2012

Can Iif be used to change query result?

I'm converting a set of queries from Access to work as stored procedures on SQL server, and one of them that uses IIF gives me a syntax error. Here's the WHERE clause of the SELECT:

WHERE IIF(@.myExtNum > 0,D.ExtentionNumber=@.myExtNum,'') AND ...

I get the error message "syntax error near '>'."

It would seem this query wants to do two things: 1) if @.myExtNum is >0, return only the rows for which D.ExtentionNumber equals a user specified value, or 2) if @.myExtNum is 0 ignore this part of the condition.

I can rewrite this using multiple ANDs and ORs, but I wodered if there was a way I could get IIF working.

Something in my gut tells me this is not going to work, that IIF is being used to modify the query; that is, change which rows are returned; it is not being used to change how a given data value is displayed, which I think was the purpose for which IIF was originally intended.

Does anyone have an insight on this?

Hello,

Sorry, but IIF isn't a valid T-SQL function. You could do this instead (if D.ExtentionNumber is not nullable):

where D.ExtentionNumber =

case

when @.myExtNum > 0 then @.myExtNum

else D.ExtentionNumber

end

If it is nullable, do this instead (the -1 is an arbitrary value that is not available to the field):

where coalesce(D.ExtentionNumber, -1) =

case

when @.myExtNum > 0 then @.myExtNum

else coalesce(D.ExtentionNumber, -1)

end

Hope this helps.

Jarret

Saturday, February 25, 2012

Can I use integrated security in an ODBC connection string without using a DSN?

Can I use integrated security in an ODBC connection string without using a
DSN?
If so, what would the syntax be for SQL Server and Oracle (if supported by
Oracle)?
TonyTrusted connection:
"Driver={SQL Server};Server=Aron1;Database=pubs;Trust
ed_Connection=yes;
"
from http://www.connectionstrings.com/ (really good source for
connectionstrings)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Tony" <tonyng2@.spacecommand.net> schrieb im Newsbeitrag
news:O4upNWsbFHA.3492@.TK2MSFTNGP14.phx.gbl...
> Can I use integrated security in an ODBC connection string without using a
> DSN?
> If so, what would the syntax be for SQL Server and Oracle (if supported by
> Oracle)?
> Tony
>|||Thanks...
Do you know of a way to connect using integrated security with Oracle?
Tony
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:Onf$jAtbFHA.2936@.tk2msftngp13.phx.gbl...
> Trusted connection:
> "Driver={SQL Server};Server=Aron1;Database=pubs;Trust
ed_Connection=ye
s;"
> from http://www.connectionstrings.com/ (really good source for
> connectionstrings)
> --
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "Tony" <tonyng2@.spacecommand.net> schrieb im Newsbeitrag
> news:O4upNWsbFHA.3492@.TK2MSFTNGP14.phx.gbl...
>|||YOu have to set a parameter in the SQLNet.Ora
http://www.windowsitpro.com/Windows...2280/42280.html
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Tony" <tonyng2@.spacecommand.net> schrieb im Newsbeitrag
news:Oq36BPwbFHA.1044@.TK2MSFTNGP10.phx.gbl...
> Thanks...
> Do you know of a way to connect using integrated security with Oracle?
> Tony
> "Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote
> in message news:Onf$jAtbFHA.2936@.tk2msftngp13.phx.gbl...
>

Can I use integrated security in an ODBC connection string without using a DSN?

Can I use integrated security in an ODBC connection string without using a
DSN?
If so, what would the syntax be for SQL Server and Oracle (if supported by
Oracle)?
Tony
Trusted connection:
"Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connect ion=yes;"
from http://www.connectionstrings.com/ (really good source for
connectionstrings)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
"Tony" <tonyng2@.spacecommand.net> schrieb im Newsbeitrag
news:O4upNWsbFHA.3492@.TK2MSFTNGP14.phx.gbl...
> Can I use integrated security in an ODBC connection string without using a
> DSN?
> If so, what would the syntax be for SQL Server and Oracle (if supported by
> Oracle)?
> Tony
>
|||Thanks...
Do you know of a way to connect using integrated security with Oracle?
Tony
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:Onf$jAtbFHA.2936@.tk2msftngp13.phx.gbl...
> Trusted connection:
> "Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connect ion=yes;"
> from http://www.connectionstrings.com/ (really good source for
> connectionstrings)
> --
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "Tony" <tonyng2@.spacecommand.net> schrieb im Newsbeitrag
> news:O4upNWsbFHA.3492@.TK2MSFTNGP14.phx.gbl...
>
|||YOu have to set a parameter in the SQLNet.Ora
http://www.windowsitpro.com/Windows/...280/42280.html
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
"Tony" <tonyng2@.spacecommand.net> schrieb im Newsbeitrag
news:Oq36BPwbFHA.1044@.TK2MSFTNGP10.phx.gbl...
> Thanks...
> Do you know of a way to connect using integrated security with Oracle?
> Tony
> "Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote
> in message news:Onf$jAtbFHA.2936@.tk2msftngp13.phx.gbl...
>

Can I Use If Condition In View

HiiiALL..
I AM CREATING A VIEW AND USE IN THIS IF AND ELSE CONDITION.
THIS SYNTAX IS NOT WORKING PROPERLY..CAN USE OR NOT??No, you can not use IF condition in a view.
There are so many other ways to do it.

Thank you.|||

Quote:

Originally Posted by iburyak

No, you can not use IF condition in a view.
There are so many other ways to do it.

Thank you.


thank u sir for reply
u say that there is many ways.
so sir what is the other way..|||1. You can create a table function.
2. You can return result of a stored procedure.
3. You can use where condition on existing view.
4. You can use Case in select statements of a view which is in many cases is almost the same as IF ELSE.
5. You can create different views and use them depend on a conditions like.
Create view View_StoredProcs
AS
select name from sysobjects where type like 'p'

Create view View_Tables
AS
select name from sysobjects where type like 'u'

and more....|||Hi iburyak,

I've used the case statement and it is working as expected here.

Thanks for the excellent explanation.|||

Quote:

Originally Posted by leniel

Hi iburyak,

I've used the case statement and it is working as expected here.

Thanks for the excellent explanation.


You are welcome.
For generic question I had a generic answer.
I am glad you were able to get some info out of it... :)
Good Luck.