What makes a Scalar Valued Function "deterministic"

Hi all,
I have the following column definition in a CREATE TABLE statement:
[Batch] AS [ÜNB] + '-' + [TypeOfData] + ' {' + CONVERT(NCHAR(4), [Validity Year])
+ '} {' + CAST([Actuality Year] AS CHAR(4)) + '-'
+ IIF([Actuality Month] < 10, '0', '')
+ CAST([Actuality Month] AS VARCHAR(2)) + '}' PERSISTED
It is accepted as deterministic by SQL Engine. When coding the same formula as a function, SQL Engine marks the function as non-deterministic.
CREATE FUNCTION [dbo].[pamDataflowBatchName]
@ÜNB VARCHAR(10), @TypeOfData VARCHAR(20) = 'Transactions', @ValidityYear SMALLINT, @ActualityYear SMALLINT = 2014, @ActualityMonth TINYINT = 5
RETURNS NVARCHAR(80)
WITH RETURNS NULL ON NULL INPUT
AS
BEGIN
DECLARE @ValidityYearOK SMALLINT = IIF(@ValidityYear <= @ActualityYear, @ValidityYear, @ActualityYear);
DECLARE @ActualityMonthOK TINYINT = IIF(@ActualityMonth > 0 AND @ActualityMonth <= 12, @ActualityMonth, 5);
RETURN @ÜNB + '-' + @TypeOfData + ' {' + CONVERT(NCHAR(4), @ValidityYearOK) + '} {' + CAST(@ActualityYear AS CHAR(4))
+ '-' + IIF(@ActualityMonthOK < 10, '0', '') + CAST(@ActualityMonthOK AS VARCHAR(2)) + '}'
END
What rules must I obey to make that function 'deterministic'?
Regards Uwe

Hi Erland,
I fully agree! The problem here is, that the SSDT-deploy automates the process intransparently and there is no chance to intervene. So the solution is casting in the CREATE TABLE which is not the right place to limit the result size. The CLR-aggregate
class has implemented this correctly using an attribute "MaxByteSize=nnnn" in the C# code so the one person gets the limit and deploy takes it and lets SQL check whether this limit is usable or not in the SQL context.
So my workaround is:
CREATE TABLE [dbo].[TestCLRFunctions]
([Computed Column One] AS CAST(dbo.[MyCLR-UDF]('A', 'B', 2010, 2014, 12) AS VARCHAR(160)) PERSISTED NOT NULL
CONSTRAINT [PK_TestCLRFunctions] PRIMARY KEY ([Computed Column One]))
Easy but bad programming practice, because two parties with different scopes have to cooperate to implement one little task. This is surely error-prone like hell. (The last sentence contains some HTML artifacts and appears blue here. No emphasizing
Regards Jörg

Similar Messages

  • Using Scalar-valued functions in a stored proc

    Hi
    I am running the following on a windows 2008 R2 Server running SQL 2008 Management server on a 64bit server  
    The following Stored Procedure:  select dbo.decryptpassword(encryptedpassword) as non_encrypted_password
    from  ..........................
    uses the following scalar function:
    USE [   ]
    GO
    /****** Object: 
    UserDefinedFunction [dbo].[DecryptPassword]   
    Script Date: 05/22/2014 14:35:11 ******/
    SET
    ANSI_NULLS ON
    GO
    SET
    QUOTED_IDENTIFIER ON
    GO
    ALTER 
    FUNCTION [dbo].[DecryptPassword](@password
    as varchar(255))
    RETURNS varchar(255)
    AS BEGIN
    DECLARE @object int
    DECLARE @hr int
    DECLARE @property
    varchar(255)
    DECLARE @return varchar(255)
    DECLARE @src varchar(255)
    DECLARE @desc varchar(255)
    -- Create an object.
    EXEC @hr =
    sp_OACreate 'Encryption.Encryption',@object
    OUT
    IF @hr <> 0
    BEGIN
       EXEC
    sp_OAGetErrorInfo @object,@src
    OUT,@desc
    OUT
    RETURN cast(@hr
    as varchar(20))
    + ' - '
    + @src + ' - '
    + @desc
    RETURN @password
    END
    -- Call a method that returns a value.
    EXEC @hr =
    sp_OAMethod @object,'DecryptString',@return
    OUT,@password
    IF @hr <> 0
    BEGIN
       EXEC
    sp_OAGetErrorInfo @object,@src
    OUT,@desc
    OUT
             RETURN
    @password
    END
    -- Destroy the object.
    EXEC @hr =
    sp_OADestroy @object
    IF @hr <> 0
    BEGIN
       EXEC
    sp_OAGetErrorInfo @object,@src
    OUT,@desc
    OUT
             END
    return  @return
    END
    When I temporarily insert  "RETURN
    cast(@hr as
    varchar(20))
    + ' - '
    + @src + ' - '
    + @desc " - I get the following:
    The return from OA-Create displays the following -2147221164  -  ODSOLE Extended Procedure - Class not registered
    The return that is committed out - "Return @password"  returns the same data as the input without decrypting the data.
    How do I solve this issue?
    GAMC

    Something is clearly amiss here. In your function you call sp_OACreate, which is used to access COM components. But then you talk about having registered a .Net assembly. Those are as far as I know different universes.
    The right course of action would be to implement DecryptPassword as a CLR function written in C# or VB .Net.
    In case you've never written a user-defined function in the CLR before, here is a dirt-simple example:
    using Microsoft.SqlServer.Server;
    using System.Data.SqlClient;
    public partial class UserDefinedFunctions
    [Microsoft.SqlServer.Server.SqlFunction]
    public static long GetTimestampF()
    return (long)
    ((double) System.Diagnostics.Stopwatch.GetTimestamp() /
    (double) System.Diagnostics.Stopwatch.Frequency * 1000000);
    Compile it with
    csc /target:library clrgettime.cs
    Create the assembly in SQL Server:
    CREATE ASSEMBLY my_first_assem FROM FILE 'c:\Temp\clrgetttime.dll'
    And then create the function:
    CREATE PROCEDURE my_first_clr_udf () RETURNS bigint AS
    EXTERNAL NAME my_first_assem.UserDefinedFunctions.GetTimestampF
    By the way, in the posting window for this forum there is an obscure button with arrows pointing from each other. You can use this button to insert code into your posts, without the forum software mangling the code.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Query with scalar valued function with date filter

    Hello experts
    i have a problem by filtering my results with the date
    i have written the following code
    SELECT
    T1.ItemCode
    , T1.Dscription
    ,DBO.F_CALCULATION_QUANTITY(T1.ITEMCODE)
    FROM OINV T0 
    INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
    INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
    WHERE
    (T0.DOCDATE BETWEEN '2010-11-01' AND '2010-11-30')
    and (t2.cardcode ='80022')
    and (T0.CANCELED= 'N')
    group by  t1.itemcode, T1.Dscription, t2.suppcatnum
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    ALTER  FUNCTION [dbo].[F_CALCULATION_QUANTITY]
    (@ITEMCODE AS NVARCHAR(10))
    RETURNS
    NUMERIC(19,2)
    AS
    BEGIN
    DECLARE
    @RESULT1 AS NUMERIC(19,2),
    @RESULT2 AS NUMERIC(19,2),
    @RESULT AS NUMERIC(19,2)
    SELECT @RESULT1=SUM(A.QUANTITY)
    FROM INV1 A
    JOIN OINV B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN  '2010-11-01 00:00:00.000' AND '2010-11-30 00:00:00.000'
    SELECT @RESULT2=SUM(A.QUANTITY)
    FROM RIN1 A
    JOIN ORIN B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN '2010-11-01 00:00:00.000' AND '2010-11-30 00:00:00.000'
    SELECT @RESULT=ISNULL(@RESULT1,0)-ISNULL(@RESULT2,0)
    --SELECT @RESULT=@RESULT1- @RESULT2
    RETURN @RESULT
    END
    the problem i have is that i want to filter my results accoring to the date provided by the user. i want it to be dynamic query.
    by now, what i do is to edit the docdate in the function in order to get the desired results. this is not what i want.
    could you please help me on this way in order to let the user to input the date?if i add the [%] in the query, it does not bring me the right results

    i have already edited the function to
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    ALTER  FUNCTION [dbo].[F_CALCULATION_QUANTITY]
    (@ITEMCODE AS NVARCHAR(10),
    @STARTDATE1 as DATETIME,
    @ENDDATE1 AS DATETIME
    RETURNS
    NUMERIC(19,2)
    AS
    BEGIN
    DECLARE
    @RESULT1 AS NUMERIC(19,2),
    @RESULT2 AS NUMERIC(19,2),
    @RESULT AS NUMERIC(19,2)
    SELECT @RESULT1=SUM(A.QUANTITY)
    FROM INV1 A
    JOIN OINV B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN (@STARTDATE1) AND (@ENDDATE1)
    SELECT @RESULT2=SUM(A.QUANTITY)
    FROM RIN1 A
    JOIN ORIN B ON A.DOCENTRY=B.DOCENTRY
    WHERE A.ITEMCODE=@ITEMCODE
    AND B.DOCDATE BETWEEN (@STARTDATE1) AND (@ENDDATE1)
    SELECT @RESULT=ISNULL(@RESULT1,0)-ISNULL(@RESULT2,0)
    RETURN @RESULT
    END
    could you please how to edit the query as well?
    i have added the following code and it comes up with the right itemcode but the quantity does not work
    DECLARE
    @ITEMCODE AS NVARCHAR(10),
    @STARTDATE1 as DATETIME,
    @ENDDATE1 AS DATETIME
    SET @STARTDATE1=(SELECT MAX(T0.DOCDATE) FROM oinv t0 WHERE T0.DOCDATE='2010-11-01')
    set @ENDDATE1=(SELECT MAX(T0.DOCDATE) FROM oinv t0 WHERE T0.DOCDATE='2010-11-30')
    SELECT
    T1.ItemCode
    , T1.Dscription
    ,DBO.F_CALCULATION_QUANTITY(@ITEMCODE,@STARTDATE1,@ENDDATE1)
    FROM OINV T0 
    INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
    INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode
    INNER JOIN OSLP T3 ON T0.SLPCODE=T3.SLPCODE
    WHERE
    (T0.DOCDATE BETWEEN @STARTDATE1 AND @ENDDATE1)
    and  (t2.cardcode ='80022')
    and (T0.CANCELED= 'N')
    group by  t1.itemcode, T1.Dscription, t2.suppcatnum
    the result is this
    70200     alert1     0.00
    70210     alert2     0.00
    70220     alert3     0.00
    70230     alert4     0.00
    as you can see the quantity is 0 and it shouldnt be
    Edited by: Fasolis Vasilios on Oct 31, 2011 10:49 AM

  • SQL: Issue with running out of storage on server when running table-valued function

    SQL Version: 2008 (not r2)
    Problem:  I'm getting the following error message when running a table-valued function:
    Msg 1105, Level 17, State 2, Line 1
    Could not allocate space for object 'dbo.SORT temporary run storage:  141072001204224' in database 'tempdb' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files
    to the filegroup, or setting autogrowth on for existing files in the filegroup.
    Request:  Could anyone tell me if there are modifications that I could make to my SQL code to avoid this storage issues?
    Thanks,
    ....bob sutor
    Code Facts:
    The JCCD table is a large table 2MM records
    The other tables in the JOINS are very small 15 records or less
    SQL Function Code:
    ALTER FUNCTION [dbo].[xcft_XAWP_GLBalance_JCCD_Detail]()
    RETURNS @JCGLDetail TABLE
          JCCo tinyint
        , Job varchar(10)
        , PostingSource varchar(10)
        , CostToDate numeric(12,2)
        , Phase varchar(20)
        , EarnType smallint
        , LiabilityType smallint
        , CostType tinyint
        , ControllingSetting varchar(30)
        , GLAccountCharged varchar(20)
        , DeptNum varchar(10)
        , DeptDesc varchar(30)
        , JCDC_CostType tinyint
        , CostTypeGL_Open varchar(20)
        , CostTypeGL_Closed varchar(20)
        , JCDO_ExcludePR varchar(1)
        , JCDO_Phase varchar(20)
        , PhaseGL_Open varchar(20)
        , PhaseGL_Closed  varchar(20)
        , JCDL_LiabType smallint
        , LiabTypeGL_Open varchar(20)
        , LiabTypeGL_Closed varchar(20)
        , JCDE_EarnType smallint
        , EarnTypeGL_Open varchar(20)
        , EarnTypeGL_Closed varchar(20)
    AS
    BEGIN
     DECLARE
     @WIPMonthCurrent date
     SET @WIPMonthCurrent = (Select TOP 1 WIPMonth FROM udxcWIPMonths WHERE ActiveWIPPeriod = 'Y')
     INSERT INTO @JCGLDetail
          JCCo
        , Job
        , PostingSource
        , CostToDate
        , Phase
        , EarnType
        , LiabilityType
        , CostType
        , DeptNum
        , DeptDesc
        , JCDC_CostType
        , CostTypeGL_Open
        , CostTypeGL_Closed
        , JCDO_ExcludePR
        , JCDO_Phase
        , PhaseGL_Open
        , PhaseGL_Closed
        , JCDL_LiabType
        , LiabTypeGL_Open
        , LiabTypeGL_Closed
        , JCDE_EarnType
        , EarnTypeGL_Open
        , EarnTypeGL_Closed
     SELECT  
         JCCD.JCCo, JCCD.Job, JCCD.Source, sum(JCCD.ActualCost) AS CostToDate, JCCD.Phase, JCCD.EarnType, JCCD.LiabilityType, JCCD.CostType
       , JCDM.Department, JCDM.Description
       , JCDC.CostType AS JCDC_CostType, JCDC.OpenWIPAcct AS CostTypeGL_Open, JCDC.ClosedExpAcct AS CostTypeGL_Closed
       , JCDO.ExcludePR AS JCDO_ExcludePR, JCDO.Phase AS JCDO_Phase, JCDO.OpenWIPAcct AS PhaseGL_Open, JCDO.ClosedExpAcct AS PhaseGL_Closed
       , JCDL.LiabType AS JCDL_LiabType, JCDL.OpenBurdenAcct AS LiabTypeGL_Open, JCDL.ClosedBurdenAcct AS LiabTypeGL_Closed
       , JCDE.EarnType AS JCDE_EarnType, JCDE.OpenLaborAcct AS EarnTypeGL_Open, JCDE.ClosedLaborAcct AS EarnTypeGL_Closed
     FROM JCCD
     LEFT JOIN JCJP ON JCCD.JCCo = JCJP.JCCo AND JCCD.Job = JCJP.Job
     LEFT JOIN JCCM ON JCJP.JCCo = JCCM.JCCo AND JCJP.Contract = JCCM.Contract
     LEFT JOIN JCDM ON JCCM.JCCo = JCDM.JCCo AND JCCM.Department = JCDM.Department
     LEFT JOIN JCDC ON JCDM.JCCo = JCDC.JCCo AND JCDM.Department = JCDC.Department AND JCCD.CostType = JCDC.CostType
     LEFT JOIN JCDE ON JCDM.JCCo = JCDE.JCCo AND JCDM.Department = JCDE.Department AND JCCD.EarnType = JCDE.EarnType
     LEFT JOIN JCDO ON JCDM.JCCo = JCDO.JCCo AND JCDM.Department = JCDO.Department AND JCCD.Phase = JCDO.Phase
     LEFT JOIN JCDL ON JCDM.JCCo = JCDL.JCCo AND JCDM.Department = JCDL.Department AND JCCD.LiabilityType = JCDL.LiabType
     LEFT JOIN xcft_XAWP_FiscalPeriodCutoffs_ForWIPMonth() AS cutoffs ON JCCD.JCCo = cutoffs.GLCo
     WHERE
          JCCD.Mth <= cutoffs.FiscalYear_LastMonth
         AND JCCD.Job IN(SELECT JobNum FROM budxcWIPData_SQL WHERE WIPMonth = @WIPMonthCurrent)
         AND JCCD.JCCo IN(SELECT JCCo FROM JCCO WHERE udExcludeFromWIP <> 'Y' or udExcludeFromWIP IS NULL)
         --AND LTRIM(RTRIM(JCCD.Job)) = '71-'
     GROUP BY
         JCCD.JCCo, JCCD.Job, JCCD.Source, JCCD.Phase, JCCD.EarnType, JCCD.LiabilityType, JCCD.CostType
       , JCDM.Department, JCDM.Description
       , JCDC.CostType, JCDC.OpenWIPAcct, JCDC.ClosedExpAcct
       , JCDO.ExcludePR, JCDO.Phase, JCDO.OpenWIPAcct, JCDO.ClosedExpAcct
       , JCDL.LiabType, JCDL.OpenBurdenAcct, JCDL.ClosedBurdenAcct
       , JCDE.EarnType, JCDE.OpenLaborAcct, JCDE.ClosedLaborAcct
     UPDATE @JCGLDetail
      SET
          ControllingSetting =
        CASE WHEN Phase = JCDO_Phase AND JCDO_ExcludePR = 'N' THEN 'PhaseOverride-PR Excluded'
          WHEN Phase = JCDO_Phase AND JCDO_ExcludePR = 'Y'
           AND EarnType NOT IN(Select EarnType FROM JCDE WHERE JCDE.JCCo = JCCo AND JCDE.Department = DeptNum)
           AND LiabilityType NOT IN(Select LiabType FROM JCDL WHERE JCDL.JCCo = JCCo AND JCDL.Department = DeptNum)
           THEN 'PhaseOverride-PR Not Excluded'
          WHEN EarnType = JCDE_EarnType THEN 'Earn Type Override'
          WHEN LiabilityType = JCDL_LiabType THEN 'Liability Type Override'
          ELSE 'Cost Type' END
     UPDATE @JCGLDetail
      SET
          GLAccountCharged =
        CASE WHEN ControllingSetting = 'PhaseOverride-PR Excluded' OR ControllingSetting = 'PhaseOverride-PR Not Excluded'
          THEN PhaseGL_Open
          WHEN ControllingSetting = 'Earn Type Override' THEN EarnTypeGL_Open
          WHEN ControllingSetting = 'Liability Type Override' THEN LiabTypeGL_Open
          ELSE CostTypeGL_Open END
    RETURN 
    END
    Bob Sutor

    well, did you either restart the instance or add another tempdb file (no restart required) to let other transactions  continue on the server.
    or check if autogrowth was limited, change that to unlimnited , to the transactions conintue..
    the function may be dumping the data on to tempdb, how much data are you excepting back...what are indexes on the tables
    Hope it Helps!!

  • Table-Valued Function not returning any results

    ALTER FUNCTION [dbo].[fGetVendorInfo]
    @VendorAddr char(30),
    @RemitAddr char(100),
    @PmntAddr char(100)
    RETURNS
    @VendorInfo TABLE
    vengroup char(25),
    vendnum char(9),
    remit char(10),
    payment char(10)
    AS
    BEGIN
    insert into @VendorInfo (vengroup,vendnum)
    select ks183, ks178
    from hsi.keysetdata115
    where ks184 like ltrim(@VendorAddr) + '%'
    update @VendorInfo
    set remit = r.remit
    from
    @VendorInfo ven
    INNER JOIN
    (Select ksd.ks188 as remit, ksd.ks183 as vengroup, ksd.ks178 as vendnum
    from hsi.keysetdata117 ksd
    inner join @VendorInfo ven
    on ven.vengroup = ksd.ks183 and ven.vendnum = ksd.ks178
    where ksd.ks192 like ltrim(@RemitAddr) + '%'
    and ks189 = 'R') r
    on ven.vengroup = r.vengroup and ven.vendnum = r.vendnum
    update @VendorInfo
    set payment = p.payment
    from
    @VendorInfo ven
    INNER JOIN
    (Select ksd.ks188 as payment, ksd.ks183 as vengroup, ksd.ks178 as vendnum
    from hsi.keysetdata117 ksd
    inner join @VendorInfo ven
    on ven.vengroup = ksd.ks183 and ven.vendnum = ksd.ks178
    where ksd.ks192 like ltrim(@PmntAddr) + '%'
    and ks189 = 'P') p
    on ven.vengroup = p.vengroup and ven.vendnum = p.vendnum
    RETURN
    END
    GO
    Hi all,
    I'm having an issue where my Table-Valued Function is not returning any results.
    When I break it out into a select statement (creating a table, and replacing the passed in parameters with the actual values) it works fine, but with passing in the same exact values (copy and pasted them) it just retuns an empty table.
    The odd thing is I could have SWORN this worked on Friday, but not 100% sure.
    The attached code is my function.
    Here is how I'm calling it:
    SELECT * from dbo.fGetVendorInfo('AUDIO DIGEST', '123 SESAME ST', 'TOP OF OAK MOUNTAIN')
    I tried removing the "+ '%'" and passing it in, but it doesn't work.
    Like I said if I break it out and run it as T-SQL, it works just fine.
    Any assistance would be appreciated.

    Why did you use a proprietary user function instead of a VIEW?  I know the answer is that your mindset does not use sets. You want procedural code. In fact, I see you use an “f-” prefix to mimic the old FORTRAN II convention for in-line functions! 
    Did you know that the old Sybase UPDATE.. FROM.. syntax does not work? It gives the wrong answers! Google it. 
    Your data element names make no sense. What is “KSD.ks188”?? Well, it is a “payment_<something>”, “KSD.ks183” is “vendor_group” and “KSD.ks178” is “vendor_nbr” in your magical world where names mean different things from table to table! 
    An SQL programmer might have a VIEW with the information, something like:
    CREATE VIEW Vendor_Addresses
    AS
    SELECT vendor_group, vendor_nbr, vendor_addr, remit_addr, pmnt_addr
      FROM ..
     WHERE ..;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • What are the possible values for the JOB status?

    What are the possible values for the JOB status in the table TBTCP and significance for each?

    Hi,
    Have a look at include LBTCHDEF.
    The standard include from SAP.
    -> Definitions and Constants for Function group BTCH
    Kind Regards
    Raymond

  • In which condition Table valued function should prefer over SP except use in joins?

    Hi, 
    My requirements is:
    Entity framework needs to call DB object (TVF or SP), which will provide some data to them and they'll work on it at app level.
    DB object would be simple, one result set, it will join 5 tables and get around 30 columns to them. it would be parameterized query so can't use view.
    Now my question is what DB object would be best to use, table valued function or store procedure. and why?
    I google on it, I find some interesting links (example http://technet.microsoft.com/en-us/library/ms187650(v=sql.105).aspx)
    they mentioned conditions to convert SP to TVF but not mentioned the reason, why I should convert?
    Both have same cache plans strategy. SP has so many advantages over TVF, but I don't see any technical advantage of TVF over SP except it can be use in joins or so. 
    so In short my question is, why I can't use SP in all cases, why I would use TVF?, and which Table valued or multi-valued?
    would appreciate your time and response.

    According to a few recent blogs you should be able to use TVP or stored procedure with EF 6.1.2 with ease. In our application we haven't switched yet to 6.1.2 (we're using 6.0.0) and there is no support for stored procedures or functions so we use StoreQuery.
    I am wondering if you can share your experience of using EF with SP or TVP (and document the steps).
    I am also wondering as how exactly it's working behind the scenes and where the full query is taking place. Say, in our case we may want to add some extra conditions after retrieving a set using, say, SP. Would the final query execute on the client (e.g.
    SP executed on the server, result returned and then extra conditions executed on the "client")?
    As I said, right now we're using StoreQuery which means that our extra conditions must be case - sensitive as opposed to SQL Server case insensitive. So, if someone already tried that scenario and can tell me how exactly it works, I would appreciate it.
    Another question about EF - I defined a property as  
     [Column(TypeName = "varchar")]
            public string PhoneNumber { get; set; } // area code + phone
    and in the LINQ query as 
    var query = db.Accounts.Select(a => new AccountsList
    AcctName = a.AcctName,
    Contact = a.Contact,
    FullName = a.FullName,
    AreaCode = a.AreaCode,
    Phone = a.Phone,
    Hidden = a.Hide,
    Hide = a.Hide,
    PhoneNumber = a.AreaCode.Trim() + a.Phone.Trim(),
    AcctTypeId = a.AcctTypeId
    and I see that it's translated into CASE AreaCode IS NULL THEN N'' ELSE RTRIM(LTRIM(areaCode)) END + ... 
    My question is - why EF does it if there is no mentioning at all in the class as how NULL is supposed to be treated. Is it a bug?
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • How to declare variable in table valued function

    hello.
    i have the following code to define a inline table valued function
    but the use of cmn.ReshteId('Lf_WL') as a function in where clause is not good performance.
    Alter function lf.fn_WholeLifeBn_GetForm(@ViewKind tinyint, @CurrentLocation int) returns table
    as
    return
    select B.*
    from lf.fn_LifeBN_GetForm(@ViewKind, @CurrentLocation) B
    where Reshte = cmn.ReshteId('Lf_WL')
    for better performance following code is good:
    declare @Reshte smallint
    set @Reshte = cmn.ReshteId('Lf_TS')
    select B.*
    from lf.fn_LifeBN_GetForm(@ViewKind, @CurrentLocation) B
    where Reshte = @Reshte
    but can not use it as the first code block in inline function.
    please help for define a good function.

    What do you think about Multi-Statement Table-Valued UDFs?
    create function Func(@Var int)
    returns @T table(ColName int)
    as
    begin
      insert into @T(ColName) values (@Var)
      return
    end
    select * from Func(10)
    select * from Func(20)
    ---or
    alter function Func()
    returns @T table(ColName int)
    as
    begin
      declare @Var int
      set @Var = 10
      insert into @T(ColName) values (@Var)
      return
    end
    select * from Func()
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • What is the default value of EO_INBOUND_PARALLEL

    Hi Gurus,
    We are on PI 7.0 EHP 1. We have not set the parameter EO_INBOUND_PARALLEL. Does this mean there is only one inbound queue registered by default if the default value is 1? However, I seem to recall that when we had issues with messages stuck in queues, I have seen more than one XBTI8 queues.
    Please help me with my doubt. thanks!

    Hi,
    Thanks for the replies.
    How about the parameter EO_INBOUND_TO_OUTBOUND and EO_OUTBOUND_PARALLEL?
    I assume by default EO_INBOUND_TO_OUTBOUND is set to 1?
    Then what is the default value for EO_OUTBOUND_PARALLEL? Plus to set this parameter you need to specify the receiver, in this case, is it true that EO_OUTBOUND_PARALLEL is not set at all so only one outbound queue? this does not make sense. Or maybe by default EO_INBOUND_TO_OUTBOUND is set to 0 so EO_OUTBOUND_PARALLEL is not used at all?
    Thanks.

  • What's the available value for weblogic.jsp.encoding in web application.

    Hi,
              I'm using chinese windows nt 4.0 and weblogic 5.1 sp6.When I did not set
              weblogic.jsp.encoding to GB2312 , when the jsp file contain's chinese , the
              output will be error .And when I did not set it , the output is correct, but
              when I use request.getParameter("SomeFormElement")(the element inputed
              chinese), the return value is error.
              How should I set weblogic.jsp.encoding value to satisfy all this problem?
              When I set the value to ISO-8859, there is an exception:
              java.io.UnsupportedEncodingException: Charset: 'ISO-8859' not recognized,
              and there is no alias for it in the weblogic.httpd.charsets property. So
              What's the available value for weblogic.jsp.encoding in web application?
              Pan
              

    hi ,
    i think the best way is to create java beans ,in that bean call your EJB ,
    and check the validation over there.
    and make that bean scope to session.
    in each and everypage try to check the session ,if it is not valid then forward to your login page...
    otherwise continue to give access to him like guest
    Regards,
    AfTaB

  • Calling User definedTable valued function in Select

    Hello,
    I Created a UserDefined Table Valued Function in HANA.
    I need to call it in Select Statement Statement.
    For Example
    Select Func(col1) as test,col2 from tablename;
    While using UserDefined Table Valued Function in above select statement
    I am getting following error
    cannot use procedure or table function in select projection
    Please help me

    Dont think you can do that Krishna,
    A Tabel UDF is expected to return a row of results and not just a scalar value. A SELECT <value> on the other hand can only expect a single value. Maybe you could try SELECT  (SELECT TOP 1 <column name> from TABLEUDF() ) from....
    Regards,
    Nehal.

  • How can i make a pl/sql function for BLOB datatype

    hi..anyone here who is very familiar about BLOB datatype. i have a COLUMN_ID, COLUMN_A in a certain TABLE_1. COLUMN_A is blob datatype that contains almost 250,000rows
    SQL>select column_A from table_1 where column_id=1234567
    column_A
    00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
    how can i make a user-defined function to compute and convert this blob datatype into decimal length value. this hex value are points in the map.. the function must contain
    1.get the length of a blob then
    2.convert blob to variable hexadecimal characters by parsing it into 8
    3.to_number function or other function used to convert haxadecimal characters to decimal numbers
    4.phythagorean formula to compute length between two points. this is the formula i think LENGTH =
    SQRT(power((coordinate_x-prev_coordinate_x),2)+power((coordinate_y-prev_y),2));
    after this when i type this
    SQL>select user_function(column_A) from table_1 where column_id=1234567
    user_functions(column_A)
    --output length will be in decimal value already
    the function will goes like this
    step1 is to get the blob length
    00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
    step2 is parsing of data by eights
    00000001 =>1
    00000001 =>1
    00000006 =>6 (number of coordinates)
    06D4E833 => X1
    074B69EC => Y1
    06D4E91F => X2
    074CO184 => Y2
    06D50C58 => X3
    074C031E => Y3
    step3 to_number function used to convert hex char to decimal
    step4 compute by phytagorean (NOTE ! when computing length the third parsed eight will tell how many coordinates are there..the number of coordinates is ranging from 2 up to E..above example shows 6 coordinates so it means
    LENGTH1 =
    SQRT(power((X2-X1),2)+power((Y2-Y1),2));
    LENGTH2=
    SQRT(power((X3-X2),2)+power((Y3-Y2),2));
    TOTAL LENGTH=LENGTH1 + LENGTH2
    thanks

    its my first time to use that.There's got to be a first tiem for anything. Be brave.
    btw if theres more easy suggestion pls feel free..Well of course the easiest solution would be if the calling program passed in the parameters as separate arguments instead of glomming them together in a string that has to be parsed. This sort of kluj really ought not to have survived into C21.
    Cheers, APC

  • What are the most important functions you cannot bypass in acrobat?

    I would like to know what are the most important functionalities that we can not bypass in Acrobat? What makes Acrobat more worthy than other PDF reader/editor?
    Personally, I notice that Acrobat (adobe products in general) takes longtime to install or uninstall. I don't find a striking feautre in Acrobat compared with other software!
    Worse, Acrobat doesn't support Multiple document interface! So, I don't know why I should pays for Adobe while other free PDF viewer/reader offer this great feature!
    Adobe does like Microsoft was doing long time ago in ignoring people opinions! I don't understand why adobe persists not to include MDI (Multiple Document Interface) at least as optional feature?
    Thanks

    The MDI issue is caused by following Windows User Interface Guidelines. Complain to Microsoft. As to what functionality is most important. The most important is creating problem free pdfs. The other things I find important are the form related capabilities, preflight, pdf optimizer and redaction.

  • What is the purpose or functions of these tables?

    Dear Experts,
    Briefly, could you explain what is the purpose or function of these tables:
    1. INOB - link between internal number and object. Is internal number = internal order number? related to project? purpose?
    2. AUSP -  Characteristic values - what characteristics? all? purpose?
    3. CABN - Characteristic : what is the purpose of this table?
    4. KLAH - Class header data : what is purpose of Class ?
    Are these cross-application like MM+SD etc or application area-specific eg MM only?
    Sorry, but i have no strong functional knowledge in these aspects. Please enlighten me.
    Thanks in advance.
    regards
    Bass

    1. INOB - link between internal number and object. Is internal number = internal order number? related to project? purpose?
    It is a linking table for internal number and object for characterstics tables.It is not relate to project.
    2. AUSP - Characteristic values - what characteristics? all? purpose?
    It will show what are the objects in class and internal characterstics.Details it will not show and it shows only numbers
    For e.gSuppose you have provided some values in Characterstics like qty 10,20..and colour ...red ,while..,Sytem will show these details in this table.
    3. CABN - Characteristic : what is the purpose of this table?
    It will show the type of characterstic is this numeric or  character
    4. KLAH - Class header data : what is purpose of Class ?
    This is also linking table.Thease are cross application tables MM+SD +PP as charactersics used in all process.

  • Returning scalar value as out parameter.

    Hi,
    I have a problem with a simple stored procedure returning a scalar value as an output parameter.
    The .NET side exception is this: bold"The data reader returned by the store data provider does not have enough columns for the query requested".*bold*
    I'm using the Entity Framework Function Import.
    This is the stored procedure:
    PROCEDURE SCALAR_RETURNING_PROCEDURE (
    EMPID IN NUMBER,
    RAISE in NUMBER,
    NEWSAL OUT NUMBER)
    IS
    BEGIN
    UPDATE EMPLOYEES E SET E.SALARY = E.SALARY+RAISE WHERE E.EMPLOYEE_ID = EMPID;
    SELECT SALARY INTO NEWSAL FROM EMPLOYEES WHERE EMPLOYEE_ID = EMPID;
    END;
    This is the function imported by EF:
    public virtual ObjectResult<Nullable<decimal>> PACKAGE2_SCALAR_RETURNING_PROCEDURE(Nullable<decimal> eMPID, Nullable<decimal> rAISE, ObjectParameter nEWSAL)
    var eMPIDParameter = eMPID.HasValue ?
    new ObjectParameter("EMPID", eMPID) :
    new ObjectParameter("EMPID", typeof(decimal));
    var rAISEParameter = rAISE.HasValue ?
    new ObjectParameter("RAISE", rAISE) :
    new ObjectParameter("RAISE", typeof(decimal));
    //HERE THE APPLICATION STOPS
    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<decimal>>("PACKAGE2_SCALAR_RETURNING_PROCEDURE", eMPIDParameter, rAISEParameter, nEWSAL);
    In a Controller of my MVC3 web application I call the function this way:
    public ActionResult ScalarValueBack()
    //Calling a stored procedure returning a scalar value...
    int empid = 1;
    int raise = 1000;
    ObjectParameter newsal = new ObjectParameter("NEWSAL", typeof(decimal));
    if (ModelState.IsValid)
    db.PACKAGE2_SCALAR_RETURNING_PROCEDURE(empid, raise, newsal);
    ViewBag.NEWSAL = newsal;
    return View();
    Environment:
    Windows 7, 64 bit
    Visual Studio 2010 Professional, Version 10.0.40219.1 SP1Rel
    .NET Framework Version 4.0.30319 SP1Rel
    Entity Framework 4.1 - Update 1
    ODAC 11.2.0.2.40 Beta 2 for Entity Framework and LINQ to Entities includes...
              Oracle Developer Tools for Visual Studio 11.2.0.2.40
              Oracle Data Provider for .NET 4 11.2.0.2.40
              Oracle Services for MTS 11.2.0.2.0
              Oracle Instant Client 11.2.0.2.0
    Oracle DB Server 11g
    Please Help Me!!!!!

    Resolved Myself.
    When importing the stored procedure via "Function Import" just choose the "None" option instead of the "Scalars" option even if
    the stored proc your're going to call will return a scalar value as an out param.
    the stored proc is the same as above..
    this is the funtion create by the function import in the dbContext class:
    public virtual int PACKAGE2_SCALAR_RETURNING_PROCEDURE(Nullable<decimal> eMPID, Nullable<decimal> rAISE, ObjectParameter nEWSAL)
    var eMPIDParameter = eMPID.HasValue ?
    new ObjectParameter("EMPID", eMPID) :
    new ObjectParameter("EMPID", typeof(decimal));
    var rAISEParameter = rAISE.HasValue ?
    new ObjectParameter("RAISE", rAISE) :
    new ObjectParameter("RAISE", typeof(decimal));
    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("PACKAGE2_SCALAR_RETURNING_PROCEDURE", eMPIDParameter, rAISEParameter, nEWSAL);
    this is the calling snippet by which I call the dbContex function (from a controller class of a .NET MVC3 Web App):
    public ActionResult ScalarValueBack()
    //Calling a stored procedure returning a scalar value...
    int empid = 1;
    int raise = 1000;
    ObjectParameter newsal = new ObjectParameter("NEWSAL", typeof(decimal));
    if (ModelState.IsValid)
    db.PACKAGE2_SCALAR_RETURNING_PROCEDURE(empid, raise, newsal);
    ViewBag.NEWSAL = newsal.Value;
    return View();
    }

Maybe you are looking for