UDF of Nvarchar(Max) type

Hi All,
Whenever some User Defined Fields is created in 2007, the underlying field is always of NVARCHAR(MAX) type. This is posing problem when creating a report on the basis of such fields in Crystal, since it does not allow to use such fields for creating links.
How to avoid this problem? It is ok to change the structure using query directly for user defined tables. Since I don't think it would require any changes in the way B1 stores the udf information.
Regards,
Rahul Jain

In my company we use this workaround:
For each table you want to link in crystal report, create a Table Key in Sap Business One as :
- Tool -> Customization Tools -> User-Defined Fields -Management
- Select the table name used in report
- Press 'Keys' Button
- Create the key selecting the fields you want to change in nvarchar(length)
Regards,
Roberto Montenovo

Similar Messages

  • B1 create User Defined Field as nvarchar(max) in SQL 2005 database

    Hi everyone,
    I just created a UDF in B1 as alphanumeric(12), and noticed that B1 created a field in SQL 2005 as nvarchar(max) instead of nvarchar(12). I tested with both 2005A SP01 patch 14 and patch 20. It always creates UDF as nvarchar(max). Is this a bug? It will cause db file use more disk space and also reduce the query performance. Also, B1 won't create the index on the UDF even if you select the option.
    Thanks for help,
    David

    Hi David,
    I was running on patch 19 when I wrote my earlier posts. I'm now running patch 20 without any issues. I also have a range of clients who are running SBO 2005A SP1 on various patch levels above 10 (though not all are on SQL 2005) and I've yet to come across this issue.
    Did you log this with SAP Support? Have they come up with any suggestions?
    Maybe this will work:
    1) Start SBO. When you get to the login screen, click on Choose Company.
    2) Change the Current Server field from SQL 2005 to SQL 2000. Reenter your server settings if prompted
    3) Login as normal and try and create your field.
    4) Log out and go back in to change back to SQL 2005
    Kind Regards,
    Owen

  • Conversion failed when converting the nvarchar value to data type int when returning nvarchar(max) from stored procedure

    Thank you for your help!!! 
    I've created a stored procedure to return results as xml.  I'm having trouble figuring out why I'm getting the error message "Conversion failed when converting the nvarchar value '<tr>.....'
    to data type int.    It seems like the system doesn't know that I'm returning a string... Or, I'm doing something that I just don't see.
    ALTER PROCEDURE [dbo].[p_getTestResults]
    @xml NVARCHAR(MAX) OUTPUT
    AS
    BEGIN
    CREATE TABLE #Temp
    [TestNameId] int,
    [MaxTestDate] [DateTime],
    [Name] [nvarchar](50),
    [Duration] [varchar](10)
    DECLARE @body NVARCHAR(MAX)
    ;WITH T1 AS
    SELECT DISTINCT
    Test.TestNameId
    , replace(str(Test.TotalTime/3600,len(ltrim(Test.TotalTime/3600))+abs(sign(Test.TotalTime/359999)-1)) + ':' + str((Test.TotalTime/60)%60,2)+':' + str(Test.TotalTime%60,2),' ','0') as Duration
    ,MaxTestDate = MAX(TestDate) OVER (PARTITION BY TM.TestNameId)
    ,TestDate
    ,TM.Name
    ,Test.TotalTime
    ,RowId = ROW_NUMBER() OVER
    PARTITION BY
    TM.TestNameId
    ORDER BY
    TestDate DESC
    FROM
    Test
    inner join TestName TM on Test.TestNameID = TM.TestNameID
    where not Test.TestNameID in (24,25,26,27)
    INSERT INTO #Temp
    SELECT
    T1.TestNameId
    ,T1.MaxTestDate
    ,T1.[Name]
    ,T1.Duration
    FROM
    T1
    WHERE
    T1.RowId = 1
    ORDER BY
    T1.TestNameId
    SET @body ='<html><body><H3>TEST RESULTS INFO</H3>
    <table border = 1>
    <tr>
    <th> TestNameId </th> <th> MaxTestDate </th> <th> Name </th> <th> Duration </th></tr>'
    SET @xml = CAST((
    SELECT CAST(TestNameId AS NVARCHAR(4)) as 'td'
    , CAST([MaxTestDate] AS NVARCHAR(11)) AS 'td'
    , [Name] AS 'td'
    , CAST([Duration] AS NVARCHAR(10)) AS 'td'
    FROM #Temp
    ORDER BY TestNameId
    FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
    SET @body = @body + @xml +'</table></body></html>'
    DROP TABLE #Temp
    RETURN @xml
    END
    closl

    Your dont need RETURN inside SP as you've declared @xml already as an OUTPUT parameter. Also you can RETURN only integer values using RETURN statement inside stored procedure as that's default return type of SP.
    so just remove RETURN statement and it would work fine
    To retrieve value outside you need to invoke it as below
    DECLARE @ret nvarchar(max)
    EXEC dbo.[P_gettestresults] @ret OUT
    SELECT @ret
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to store a query containing more than 15000 characters in a variable of nvarchar(max)

    I have the following string and I want to store it in variable using SQL Server 2008 R2 . I can't store this string using variable of nvarchar(max) .
    ' SELECT    A.[EmployeeCode] ,A.[EmployeeId] ,A.[Name],A.[DepartmentCode],A.[DesignationCode]   
    , A.[CompanyCode]  ,A.[Department] ,A.[Designation] ,A.[Entity]
    , A.[GovtAdministrativeAreaCode]   ,A.[WorkingUnitCode],A.[WorkingUnitName]
    , isnull(L.WorkingDays ,0) as  TotalWorkingDays ,isnull(K.DelayHr,0) as DelayHr
    , isnull(J.OTHr,0) as OTHr ,isnull(B.[4Hr],0) as [4Hr]
    , isnull(C.[10Hr],0) as [10Hr] ,isnull(D.[12Hr],0) as [12Hr]
    , isnull(E.NoOfPresent,0) as NoOfPresent   , isnull(F.NoOfAbsent,0 )as NoOfAbsent
    , isnull(G.NoOfLeave ,0) as NoOfLeave , isnull(H.Morning ,0) as Morning
    , isnull(I.Night,0) as Night , isnull(L.[NoOfW/HDay] ,0) as [NoOfW/HDay]
    , isnull(K.NoOfDelay,0) as NoOfDelay , isnull(L.TotalDayAttends,0) as TotalDayAttends
    , isnull(M.[LessThan4Hr] ,0) as [LessThan4Hr]
    , isnull (N.NoOfNoOutTime,0) as NoOfNoOutTime
    INTO '
    +@tableName+'
    FROM
    ( SELECT DISTINCT [EmployeeCode] ,[EmployeeId] ,[Name],[DepartmentCode],[DesignationCode]
      ,[CompanyCode]  ,[Department] ,[Designation] ,[Entity]
      ,[GovtAdministrativeAreaCode]   ,[WorkingUnitCode],[WorkingUnitName]
      FROM [vwHR_DailyAttendanceSummary]
      WHERE AttendanceDate between  dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''')
    ) A
    LEFT JOIN
    (   SELECT [EmployeeCode]     ,WorkingUnitCode      ,Count([AttendanceDate] ) as [4Hr]
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode]  
      FROM [vwHR_DailyAttendanceSummary]
      WHERE AttendanceDate between   dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''')
      and (DATEDIFF(MINUTE,InTime,OutTime))/60 >=4 and (DATEDIFF(MINUTE,InTime,OutTime))/60 <10
      group by EmployeeCode ,WorkingUnitCode   ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode]  
    ) B ON (B.EmployeeCode=A.EmployeeCode and B.WorkingUnitCode=A.WorkingUnitCode
    and B.DepartmentCode=A.DepartmentCode and B.DesignationCode=A.DesignationCode and B.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode)
    LEFT JOIN
    (       SELECT [EmployeeCode]      ,WorkingUnitCode       ,Count([AttendanceDate] ) as [10Hr]
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode]     
    FROM [vwHR_DailyAttendanceSummary]
    WHERE AttendanceDate between    dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''') 
    and (DATEDIFF(MINUTE,InTime,OutTime))/60 >=10 and (DATEDIFF(MINUTE,InTime,OutTime))/60 <12
    group by EmployeeCode,WorkingUnitCode  ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode]   
    )C ON (C.EmployeeCode=A.EmployeeCode and C.WorkingUnitCode=A.WorkingUnitCode
    and C.DepartmentCode=A.DepartmentCode and C.DesignationCode=A.DesignationCode and C.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode)
    LEFT JOIN
    (   SELECT [EmployeeCode]     ,WorkingUnitCode   ,Count([AttendanceDate] ) as [12Hr]
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode]     
      FROM [vwHR_DailyAttendanceSummary]
      WHERE AttendanceDate between  dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''')
      and (DATEDIFF(MINUTE,InTime,OutTime))/60 >=12
      group by EmployeeCode,WorkingUnitCode    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
    ) D on (D.EmployeeCode=A.EmployeeCode and D.WorkingUnitCode=A.WorkingUnitCode
    and D.DepartmentCode=A.DepartmentCode and D.DesignationCode=A.DesignationCode and D.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode)
    LEFT JOIN
    (   SELECT [EmployeeCode]  ,WorkingUnitCode   ,COUNT(Status) NoOfPresent
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
      FROM [vwHR_DailyAttendanceSummary]
      WHERE Status = ''P'' and AttendanceDate between   dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''') 
      group by EmployeeCode,WorkingUnitCode,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
      ) E on (E.EmployeeCode =A.EmployeeCode and E.WorkingUnitCode=A.WorkingUnitCode
    and E.DepartmentCode=A.DepartmentCode and E.DesignationCode=A.DesignationCode and E.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode)
    LEFT JOIN
      (   SELECT [EmployeeCode],WorkingUnitCode  ,COUNT(Status) NoOfAbsent
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
      FROM [vwHR_DailyAttendanceSummary]
      WHERE Status = ''A'' and AttendanceDate between  dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''')
      group by EmployeeCode,WorkingUnitCode  ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
    ) F on (F.EmployeeCode=A.EmployeeCode and F.WorkingUnitCode = A.WorkingUnitCode
    and F.DepartmentCode=A.DepartmentCode and F.DesignationCode=A.DesignationCode and F.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode)
    LEFT JOIN
           ( SELECT  la.CompanyCode , la.EmployeeCode ,lad.LeaveDate ,A.WorkingUnitCode,A.DepartmentCode,A.DesignationCode,W.AdminAreaCode
    FROM [vwLMS_EmployeeLeaveInformation] la
    inner JOIN LMS_LeaveApplicationDetail  lad on (lad.LeaveApplicationCode=la.LeaveApplicationCode and lad.ActionType <> ''DELETE'')
    inner join HR_DailyAttendanceSummary A on (A.EmployeeCode=la.EmployeeCode and A.AttendanceDate=lad.LeaveDate and A.ActionType <> ''DELETE'')
    inner join General_WorkingUnit W on (w.WorkingUnitCode=A.WorkingUnitCode and W.ActionType <> ''DELETE'')
    WHERE  la.ApplicationStatus=1 and  la.JobStatus in (1,0)
    and lad.LeaveDate between   dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''')  
    ) G  on ( G.EmployeeCode=A.EmployeeCode and G.WorkingUnitCode=A.WorkingUnitCode
    and G.DepartmentCode= A.DepartmentCode and G.DesignationCode= A.DesignationCode and G.AdminAreaCode=A.GovtAdministrativeAreaCode)
    LEFT JOIN
    (   SELECT [EmployeeCode] ,WorkingUnitCode ,Count([AttendanceDate] ) as [Morning] 
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode]        
      FROM [vwHR_DailyAttendanceSummary]
      WHERE AttendanceDate between  dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''')
      and (DATEDIFF(MINUTE,InTime,OutTime))/60 >=8 and DATEPART(HH,InTime)=6 and DATEPART(HH,OutTime)>=14
      group by EmployeeCode,WorkingUnitCode    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
    ) H On (H.EmployeeCode=A.EmployeeCode and H.WorkingUnitCode=A.WorkingUnitCode
    and H.DepartmentCode=A.DepartmentCode and H.DesignationCode=A.DesignationCode and H.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode)
    LEFT Join
    (   SELECT [EmployeeCode]   ,WorkingUnitCode       ,Count([AttendanceDate] ) as [Night]
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode]          
      FROM [vwHR_DailyAttendanceSummary]
      WHERE AttendanceDate between    dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''')
      and (DATEDIFF(MINUTE,OutTime,InTime))/60 >=8
      and DATEPART(HH,InTime)>=19
      and DATEPART(HH,OutTime)>=5
      group by EmployeeCode ,WorkingUnitCode ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
    ) I on (I.EmployeeCode=A.EmployeeCode and I.WorkingUnitCode=A.WorkingUnitCode
    and I.DepartmentCode=A.DepartmentCode and I.DesignationCode=A.DesignationCode and I.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode)
    LEFT JOIN
    ( SELECT distinCt [EmployeeCode]
    ,sum(TotalOverTime ) as OTHr
    ,WorkingUnitCode
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
    FROM vwHR_DayBasisOvertime  
    WHERE AttendanceDate between   dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''')
    group by EmployeeCode ,WorkingUnitCode ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
    ) J ON (J.EmployeeCode=A.EmployeeCode and J.WorkingUnitCode=A.WorkingUnitCode
    and J.DepartmentCode=A.DepartmentCode and J.DesignationCode=A.DesignationCode and J.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode)  
    LEFT JOIN  
    (   SELECT distinCt A.[EmployeeCode]  
    ,DelayHr=CASE
    WHEN sum(DATEDIFF(mi,A.AttendanceDate + A.ShifIn, A.InTime)) >0 THEN SUM( DATEDIFF(mi,A.AttendanceDate +A.ShifIn, A.InTime))
    WHEN sum(DATEDIFF(mi,A.AttendanceDate +A.ShifIn, A.InTime))<0 THEN 0
    END
    ,Count(A.AttendanceDate) as NoOfDelay
    , WorkingUnitCode
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
      FROM [vwHR_DailyAttendanceSummary] A
      WHERE A.Status=''D'' AND AttendanceDate between   dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''') 
      group by A.EmployeeCode ,WorkingUnitCode,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
    ) K On (K.EmployeeCode=A.EmployeeCode and K.WorkingUnitCode=A.WorkingUnitCode
    and K.DepartmentCode=A.DepartmentCode and K.DesignationCode=A.DesignationCode and K.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode)
    INNER JOIN
    ( select  EmployeeCode ,WorkingUnitCode 
    /*, [A/L Time],[No Of A/L Day],[Total Working Day Time] */
    , [No Of working Day] as WorkingDays
    , ([No Of W Day]+[No Of H Day]) as [NoOfW/HDay]
    ,[Total At] as TotalDayAttends
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
    from '
    +@OutPutTableName_WorkingDaysHours+'
    ) L ON (L.EmployeeCode=A.EmployeeCode and l.WorkingUnitCode=A.WorkingUnitCode
    and L.DepartmentCode=A.DepartmentCode and L.DesignationCode=A.DesignationCode and L.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode)
    LEFT JOIN
    (   SELECT [EmployeeCode]  ,WorkingUnitCode ,Count([AttendanceDate] ) as [LessThan4Hr] 
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode]   
      FROM [vwHR_DailyAttendanceSummary]
      WHERE AttendanceDate between   dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''')
      and (DATEDIFF(MINUTE,InTime,OutTime))/60 >0 and (DATEDIFF(MINUTE,InTime,OutTime))/60 <4
      group by EmployeeCode,CompanyCode ,WorkingUnitCode    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
    ) M ON (M.EmployeeCode=A.EmployeeCode and M.WorkingUnitCode=A.WorkingUnitCode
    and M.DepartmentCode=A.DepartmentCode and M.DesignationCode=A.DesignationCode and M.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode )
    left join
    ( SELECT EmployeeCode  ,WorkingUnitCode , COUNT(AttendanceDate) as NoOfNoOutTime
    ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode]  
    FROM vwHR_DailyAttendanceSummary
    WHERE  AttendanceDate between dbo.fxn_cDate('''
    +@DateFrom+''')
    and dbo.fxn_cDate('''+@DateTo+''') 
    and OutTime is null
    group by EmployeeCode ,WorkingUnitCode ,[DepartmentCode] ,[DesignationCode]    ,[GovtAdministrativeAreaCode] 
    ) N ON (N.EmployeeCode=A.EmployeeCode and N.WorkingUnitCode=A.WorkingUnitCode
    and N.DepartmentCode=A.DepartmentCode and N.DesignationCode=A.DesignationCode and N.GovtAdministrativeAreaCode=A.GovtAdministrativeAreaCode)

    If you are concatenating multiple strings together to make a nvarchar(max), and the result is too long to store in the largest possible regular regular nvarchar (that is nvarchar(4000), you must be sure the concatenation is done as nvarchar(max).  If
    you don't, each of the concatenations is done according to the type of each operand.  And, if the two things being concatenated are both (for example) nvarchar(20), then the result is nvarchar(40) because 20+20 is 40.  But if the two things being
    concatenated are both nvarchar(3000), the result does not become nvarchar(max), it is nvarchar(4000) - because 3000 + 3000 is 6000, but that's two big, so you get 4000.  For a simple example
    Declare @Result nvarchar(max), @Input1 nvarchar(3000), @Input2 nvarchar(3000);
    Set @Input1 = Replicate('a', 3000);
    Set @Input2 = Replicate('b', 3000);
    Set @Result = @Input1 + @Input2;
    Select 'Test1', Len(@Result), Len(@Input1), Len(@Input2);
    Set @Result = Cast(@Input1 As nvarchar(max)) + @Input2;
    Select 'Test2', Len(@Result), Len(@Input1), Len(@Input2);
    In Test1, the two 3000 character nvarchars are concatenated together, but the result is truncated to nvarchar(4000).  That is then put in an nvarchar(max), but the result is already truncated to 4000 characters, so in Test1 the length of @Result is
    4000.  In Test2, the first operand is converted to nvarchar(max), so the concatenation result is nvarchar(max) and you get the length you expect in @Result (that is, 6000).
    So the solution to your problem is to force the first item in your concatenation to be of type nvarchar(max).  Then the result of the concatenation of the first and second will be nvarchar(max), then SQL concatenates the third term and gets nvarchar(max),
    etc.  So the final result contains the whole string you want.  So you want to do
    CAST(' SELECT A.[EmployeeCode] ,A.[EmployeeId] ,A.[Name],A.[DepartmentCode],A.[DesignationCode]
    , A.[CompanyCode] ,A.[Department] ,A.[Designation] ,A.[Entity]
    , A.[GovtAdministrativeAreaCode] ,A.[WorkingUnitCode],A.[WorkingUnitName]
    , isnull(L.WorkingDays ,0) as TotalWorkingDays ,isnull(K.DelayHr,0) as DelayHr
    , isnull(J.OTHr,0) as OTHr ,isnull(B.[4Hr],0) as [4Hr]
    , isnull(C.[10Hr],0) as [10Hr] ,isnull(D.[12Hr],0) as [12Hr]
    , isnull(E.NoOfPresent,0) as NoOfPresent , isnull(F.NoOfAbsent,0 )as NoOfAbsent
    , isnull(G.NoOfLeave ,0) as NoOfLeave , isnull(H.Morning ,0) as Morning
    , isnull(I.Night,0) as Night , isnull(L.[NoOfW/HDay] ,0) as [NoOfW/HDay]
    , isnull(K.NoOfDelay,0) as NoOfDelay , isnull(L.TotalDayAttends,0) as TotalDayAttends
    , isnull(M.[LessThan4Hr] ,0) as [LessThan4Hr]
    , isnull (N.NoOfNoOutTime,0) as NoOfNoOutTime
    INTO ' AS nvarchar(max))
    +@tableName+'
    --- Etc for the rest of your expression
    Tom

  • Like operator not passed to database for nvarchar(max)

    From Crystal Reports 2008 I need to do a keyword search against a data type of nvarchar(max).
    I am using the LIKE operator in my record selection formula.
    When I do a SHOW QUERY the LIKE condition is omitted from the where clause.
    This makes the report run so slow it is useless.
    How can I do a keyword search against an nvarchar(max) data type?
    Thanks,
    Larry
    CR Developer 12.2.0.290, Product type: Full
    SQL Server 2008 r2

    Sorry it wasn't clear what you are doing or why. I assumed you were using the LIKE in the record selection formula to filter on fields like CustomerID etc. which can be passed to the server. You want to filter based on the text in a Description type field field.
    Yes that is going to be very slow having Crystal do it client side, means all of the data will be sent to the local work station and then on the second pass CR will start filtering.
    You could try using a Command Object to use as the data source, CR should simply pass what ever SQL you type in. Copy your existing SQL and then create a new report and use a Command object and paste in the SQL, edit it to include the LIKE operator and see it that works for you.
    Another option is to use a Stored Procedure with a parameter to do the searching, that will force it to do it Server side. DB servers will aways be more efficient at processing filters that ce will be.
    When viewing the report can you not use the Search window, although that is after the fact so it too would mean all data has to come down first...?
    Basically what is happening is CR is testing every word in the nvarchar field, CR isn't very optimized to do that kind of filtering client side and because it's more complex SQL we won't generate the proper syntax to pass it to the server. Also, Cr supports so many data sources and to build that logic into the basic report designer is very complex and not efficient, there are various DB tools that can do that kind of work and CR can connect to them, Universes, Data Integrator etc., those tools are designed to do this type of complex SQL generation.
    Thank you
    Don
    PS - If Jason sees this thread he is a SQL guru and may have some suggestion for you also.
    Edited by: Don Williams on Jun 22, 2011 11:17 AM

  • How to compare 2 NVARCHAR(MAX) columns in same table ?

    I have 2 strings i am trying to compare them ,If user changes some data then insert should happen to change log table .
    here is the condition i am using it
    If dbo.RemoveMultipleSpacesItr(@ProgBusSolPrev) <> dbo.RemoveMultipleSpacesItr(@ProgBusSol)
    begin
    Insert into ptt_pmt_import_ch(ProgramID,ColumnName,Prev_Value,New_Value,UpdatedBy) values(@Programid,'Solution to Problem',@ProgBusSolPrev,@ProgBusSol,@UpdatedBy)
    end
    My Scalar Function to compare 2 strings and replace spaces in strings.
    CREATE FUNCTION dbo.RemoveMultipleSpacesItr(@str NVARCHAR(MAX))
    RETURNS NVARCHAR(MAX)
    AS
    BEGIN
    WHILE CHARINDEX(' ', @str) > 0
    SET @str = REPLACE(@str, ' ', '');
    RETURN @str;
    END
    If my Input values for
    @ProgDescriptionPrev='These issues are creating missed appointments and unnecessary scheduling techs on appt that are not needed. This impacts areas that are in an overbooking situation. Potentially overbooks appts during specific time of day, and increases Appt misses. Potentially decreasing Appts met by .3%, which has potential customer services impacts of 10K per year. This impacts Load Supervisors as they have to manually calculate worksteam percentage allocations. Estimating 20 users a day * 30mins= 50hrs week =1.1 Supervisor HC= 90K year. IT HelpDesk Tickets (sometimes duplicate) are also opened by front-line agents and are unable to be resolved. So this is a total of about 100k+ a year in cost savings/avoidance.'
    @ProgDescription='These issues are creating missed appointments and unnecessary scheduling techs on appt that are not needed. This impacts areas that are in an overbooking situation. Potentially overbooks appts during specific time of day, and increases Appt misses. Potentially decreasing Appts met by .3%, which has potential customer services impacts of 10K per year. This impacts Load Supervisors as they have to manually calculate worksteam percentage allocations. Estimating 20 users a day * 30mins= 50hrs week =1.1 Supervisor HC= 90K year. IT HelpDesk Tickets (sometimes duplicate) are also opened by front-line agents and are unable to be resolved. So this is a total of about 100k+ a year in cost savings/avoidance.'
    Only difference in strings is space(' ')
    if there is no difference in strings avoiding spaces in strings, i need to insert into change log. But using above query even there is no change in string values it inserts in to change log table.Please help on this,i need solution for this
    sonali malla

    Hi,,,
    Are you lecturing my dynamic script? Thither is a solution for this problem - we can convert all column values to nvarchar(max) first - most common types can be converted to nvarchar(max) and only some exotic types cannot be converted.
    Here is the script using nvarchar(max):
    CREATE TABLE Test1(id INT,col2 INT,col3 INT, col4 int, col5 varchar(10), col6 date)
    CREATE TABLE Test2(id INT,col2 INT,col3 INT, col4 int, col5 varchar(10), col6 date)
    INSERT INTO Test1 VALUES (1,2,3,9,'q', '20120101'),(4,5,6,10,'z','20120404')
    INSERT INTO Test2 VALUES (1,2,7,8, 'm','19990101'),(4,8,6,12, 'dd','20110505')
    declare @sql nvarchar(max), @Cols nvarchar(max)
    select @Cols = stuff((select ',(cast(' + QUOTENAME(column_name) + ' as nvarchar(max)),' +
    QUOTENAME(column_name,'''') + ')' from Information_schema.columns C
    where C.TABLE_SCHEMA = 'dbo' and c.TABLE_NAME = 'Test1' and c.COLUMN_NAME <> 'id'
    order by c.COLUMN_NAME for XML path('')),1,1,'')
    set @sql = 'SELECT t1.c as [Column Name] , t1.col as [Expected Value], t2.col as [Actual Value]
    FROM (select id, c, col from Test1 cross apply (values' + @Cols + ' ) d(col, c) ) t1
    INNER JOIN
    (select id, c, col from Test2 cross apply (values' + @Cols+ ' ) d(col, c) ) t2
    ON t1.id=t2.id AND t1.c=t2.c
    WHERE t1.col<>t2.col
    Order by t1.c'
    print @sql
    execute (@sql)
    If Any other Concern, let me know.
    Thanks :-)

  • ORA-28500 + "String data, right truncation" when selecting nvarchar(max)

    Hi,
    I was able to set up a db link from Oracle 11.2.0.1 to SQL Server 2005 using DG4ODBC.
    When trying to select a column with nvarchar(max) datatype from the db link I get the following error:
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}
    ORA-02063: preceding 2 lines from SQLSERVER_DBLINKThe actual data in the column doesn't exceed 31 chars but the query still fails.
    Any suggestions?
    Thanks.

    The character set is AL32UTF8
    Here is the relevant data from the trace file:
    Entered hgopars, cursor id 1 at 2010/12/23-12:08:59
    type:0
    SQL text from hgopars, id=1, len=47 ...
         00: 53454C45 43542041 312E2243 6F6D6D65  [SELECT A1."Comme]
         10: 6E742220 46524F4D 20224442 4F222E22  [nt" FROM "DBO"."]
         20: 565F4442 56455253 494F4E22 204131    [V_DBVERSION" A1]
    Exiting hgopars, rc=0 at 2010/12/23-12:08:59
    hostmstr: 2011148288:      HOA After hoxpars
    hostmstr: 2011148288:      HOA Before hoxopen
    Entered hgoopen, cursor id 1 at 2010/12/23-12:08:59
    hgoopen, line 87: NO hoada to print
    Deferred open until first fetch.
    Exiting hgoopen, rc=0 at 2010/12/23-12:08:59
    hostmstr: 2011148288:      HOA After hoxopen
    hostmstr: 2011148288:      HOA Before hoxdscr
    Entered hgodscr, cursor id 1 at 2010/12/23-12:08:59
    Allocate hoada @ 038B493C
    Entered hgopcda at 2010/12/23-12:08:59
    Column:1(Comment): dtype:-9 (WVARCHAR), prc/scl:0/0, nullbl:1, octet:0, sign:1, radix:0
    Exiting hgopcda, rc=0 at 2010/12/23-12:08:59
    hgodscr, line 910: Printing hoada @ 038B493C
    MAX:1, ACTUAL:1, BRC:100, WHT=5 (SELECT_LIST)
    hoadaMOD bit-values found (0x40:TREAT_AS_NCHAR)
    DTY         NULL-OK  LEN  MAXBUFLEN   PR/SC  CST IND MOD NAME
    12 VARCHAR Y          0          0 128/  0 1000   0  40 Comment
    Exiting hgodscr, rc=0 at 2010/12/23-12:08:59
    hostmstr: 2011148288:      HOA After hoxdscr
    hostmstr: 2011148288: RPC After SQL Bundling
    hostmstr: 2011148288: RPC Before SQL Bundling
    hostmstr: 2011148288:      HOA Before hoxclse
    Entered hgoclse, cursor id 1 at 2010/12/23-12:08:59
    Exiting hgoclse, rc=0 at 2010/12/23-12:08:59
    hostmstr: 2011148288:      HOA After hoxclse
    hostmstr: 2011148288:      HOA Before hoadafr
    Entered hgodafr, cursor id 1 at 2010/12/23-12:08:59
    Free hoada @ 038B493C
    Exiting hgodafr, rc=0 at 2010/12/23-12:08:59
    hostmstr: 2011148288:      HOA After hoadafr
    hostmstr: 2011148288:      HOA Before hoxpars
    Entered hgopars, cursor id 1 at 2010/12/23-12:08:59
    type:0
    SQL text from hgopars, id=1, len=47 ...
         00: 53454C45 43542041 312E2243 6F6D6D65  [SELECT A1."Comme]
         10: 6E742220 46524F4D 20224442 4F222E22  [nt" FROM "DBO"."]
         20: 565F4442 56455253 494F4E22 204131    [V_DBVERSION" A1]
    Exiting hgopars, rc=0 at 2010/12/23-12:08:59
    hostmstr: 2011148288:      HOA After hoxpars
    hostmstr: 2011148288:      HOA Before hoxopen
    Entered hgoopen, cursor id 1 at 2010/12/23-12:08:59
    hgoopen, line 87: NO hoada to print
    Deferred open until first fetch.
    Exiting hgoopen, rc=0 at 2010/12/23-12:08:59
    hostmstr: 2011148288:      HOA After hoxopen
    hostmstr: 2011148288:      HOA Before hoxdscr
    Entered hgodscr, cursor id 1 at 2010/12/23-12:08:59
    Allocate hoada @ 038B6C98
    Entered hgopcda at 2010/12/23-12:08:59
    Column:1(Comment): dtype:-9 (WVARCHAR), prc/scl:0/0, nullbl:1, octet:0, sign:1, radix:0
    Exiting hgopcda, rc=0 at 2010/12/23-12:08:59
    hgodscr, line 910: Printing hoada @ 038B6C98
    MAX:1, ACTUAL:1, BRC:100, WHT=5 (SELECT_LIST)
    hoadaMOD bit-values found (0x40:TREAT_AS_NCHAR)
    DTY         NULL-OK  LEN  MAXBUFLEN   PR/SC  CST IND MOD NAME
    12 VARCHAR Y          0          0 128/  0 1000   0  40 Comment
    Exiting hgodscr, rc=0 at 2010/12/23-12:08:59
    hostmstr: 2011148288:      HOA After hoxdscr
    hostmstr: 2011148288: RPC After SQL Bundling
    hostmstr: 2011148288: RPC Before Fetch Row
    hostmstr: 2011148288:      HOA Before hoaftch
    Entered hgoftch, cursor id 1 at 2010/12/23-12:08:59
    hgoftch, line 130: Printing hoada @ 038B6C98
    MAX:1, ACTUAL:1, BRC:100, WHT=5 (SELECT_LIST)
    hoadaMOD bit-values found (0x40:TREAT_AS_NCHAR)
    DTY         NULL-OK  LEN  MAXBUFLEN   PR/SC  CST IND MOD NAME
    12 VARCHAR Y          0          0 128/  0 1000   0  40 Comment
    Performing delayed open.
    SQLBindCol: column 1, cdatatype: -8, bflsz: 2
    Entered hgopoer at 2010/12/23-12:08:59
    hgopoer, line 233: got native error 0 and sqlstate 01004; message follows...
    [Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}
    Exiting hgopoer, rc=0 at 2010/12/23-12:08:59
    hgoftch, line 740: calling SQLFetch got sqlstate 01004
    Entered hgopoer at 2010/12/23-12:08:59
    hgopoer, line 233: got native error 0 and sqlstate 01004; message follows...
    [Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}[Microsoft][SQL Native Client]String data, right truncation {01004}
    Exiting hgopoer, rc=0 at 2010/12/23-12:08:59
    hgoftch, line 971: calling SQLGetData got sqlstate 01004
    100 rows fetched
    Exiting hgoftch, rc=28500 at 2010/12/23-12:08:59 with error ptr FILE:hgoftch.c LINE:971 ID:Row error while doing array fetch
    hostmstr: 2011148288:      HOA After hoaftch
    hostmstr: 2011148288: RPC After Fetch RowThanks

  • The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.

    Below select statement results in "The conversion of a nvarchar data type to a datetime data type resulted in an out of range value"   error. By the way Terms
    field's data type is nvarchar
     SELECT * from INVOICE
    where convert(datetime,Terms) 
    BETWEEN
    '01/01/14'
    and
    '01/30/15' 

    If you can't use TRY_CONVERT (It's only available in 2012+) You should be able to validate the data with something like this (based on your example date formats):
    DECLARE @notDate TABLE (Terms NVARCHAR(10))
    INSERT INTO @notDate (Terms) VALUES
    ('01/01/14'),('02/29/14'),('01/32/15'),('13/13/14'),('13/3/14'),('13-13/14'),('02/29/12'),('02/29/13')
    SELECT *,
    CASE WHEN (LEN(Terms) - 2) <> LEN(REPLACE(Terms,'/','')) OR LEN(Terms) <> 8 THEN 'Bad Form'
    WHEN LEFT(Terms,2) > 12 THEN 'Bad Month'
    WHEN LEFT(Terms,2) IN (9,4,6,11) AND LEFT(RIGHT(Terms,5),2) > '30' THEN 'Bad Day'
    WHEN LEFT(Terms,2) = 2 AND LEFT(RIGHT(Terms,5),2) > (28 + CASE WHEN (2000+RIGHT(Terms,2)) % 400 = 0 THEN 1 WHEN (2000+RIGHT(Terms,2)) % 100 = 0 THEN 0 WHEN (2000+RIGHT(Terms,2)) % 4 = 0 THEN 1 ELSE 0 END) THEN 'Bad Day'
    WHEN LEFT(Terms,2) NOT IN (2,9,4,6,11) AND LEFT(RIGHT(Terms,5),2) > '31' THEN 'Bad Day'
    END
    FROM @notDate
    Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.

  • Nvarchar(max) of sql server 2005 is not accessible through Oracle DB Link

    hi,
    i have created the DB LINK from Oralce 11gR2 to MS Sql Server 2005,
    am able to access the view of Sql Server from Oralce,
    but the Columns which have Datatype nvarchar(max) in Sql Server am not able to access through DB Link.
    can anybody know about this issues?

    Pl do not post duplicate threads - Datatype nvarchar(max) not accessable (DB Link from Sql 2005 to Ora 11gR2 )

  • How to dump table to the flat file, if the table has NVARCHAR data type fie

    I need to dump the table to the text file. The table has NVARCHAR data type field and simple select * from table_name does not work. What do I have to do? Do I need convert NVARCHAR to VARCHAR and if yes, then how?
    Thanks,
    Oleg

    I need to dump the table to the text file. The table has NVARCHAR data type field and simple select * from table_name does not work. What do I have to do? Do I need convert NVARCHAR to VARCHAR and if yes, then how?
    Thanks,
    Oleg

  • NVARCHAR (MAX) TO PRINT DYNAMIC SQL QUERY TO A SQL FILE

    Hi 
    I have a requirement where i need to write an SP which would construct a huge query using dynamic SQL and save the Dynamic query to a file. 
    The Dynamic SQL Variable I am using as @NVARCHAR(MAX) but since the query being built is large (>4000 characters), I am not able to select it into a table. PRINT @SQL prints the whole query but SELECT @SQL prints only upto 4000 characterrs. 
    And I need to save this huge dynamix sql to a file using the SP.
    Any thoughts as to how i can achieve this?
    Rajiv

    This is a know problem with dynamic SQL nvarchar(max) concatenation.
    See below for correct assembly of large SQL strings:
    CREATE table #temp(qry nvarchar(max));
    declare @cmd nvarchar(max);
    SELECT @cmd=CONCAT(CONVERT(nvarchar(max),N'SELECT '),
    CONVERT(nvarchar(max),REPLICATE (N'A',4000)),
    CONVERT(nvarchar(max),REPLICATE (N'A',4000)),
    CONVERT(nvarchar(max),REPLICATE (N'A',4000)),
    CONVERT(nvarchar(max),REPLICATE (N'A',4000)),
    CONVERT(nvarchar(max),N'FROM SYS.TABLES'));
    insert into #temp SELECT @cmd;
    select * from #temp;
    select len(qry), datalength(qry) from #temp;
    -- 16022 32044
    drop table #temp;
    Dynamic SQL:  http://www.sqlusa.com/bestpractices/dynamicsql/
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Does owb support nvarchar data type?

    When i imported a source table from oracle9.i database,it can not import nvarchar type column.
    How to support it?
    thx

    I suppose you mean NVARCHAR2, there is no such datatype as NVARCHAR.
    NVARCHAR2 is currently not supported, but it will be in the next major release. The workaround now is to write a view to translate NVARCHAR2 into supported type VARCHAR2.
    Nikolai Rochnik

  • Inconsistency during recon with UDF fields with date type

    We have several fields type Date in the UDF definition. Birthdate, for example.
    We recon'd a bunch of users, and some users have their birthdate (and other dates, like start and end dates UDF) showing up at YYYY/MM/DD 00:00:00 in the database, while others show up as YYYY/MM/DD 01:00:00
    This obviously is bad. Has anyways seen this behavior before?
    Thanks.

    Hi Hiney,
    I am not sure what version of OIM you are, but I got errors like yours last year and it was resolved with an article (Oracle Metalink) ID 1146555.1. Please go there and let me know if you are facing the same issue that I got. And follow the solution there.
    I hope this helps.
    Thiago Leoncio Guimaraes

  • How to add a UDF with picture data type by using metadata object?

    Hi guys,
    does anybody have a clue on how to code user fields metadata object (via VB6) in order to add a picture type field? I can't find the enum number for this data type in the DI help file.
    Best Regards,
    Oki

    Hi,
    The field type should be BoFieldTypes.db_Alpha , and the subtype BoFldSubTypes.st_Image .
    And it is in the DI documentation (look at the SubType property).
    Regards,
    Ibai Peñ

  • Fact table data type changed from int to nvarchar -- rebuild on cube fails

     I change one of my data types in the Fact table from INT to Nvarchar... When I look at the properties it appears
    correct but when I try to Process it fails still thinking it's data type INT.
     How can the DSV be refreshed( I did try REFRESH  and it noticied the change to field) to reflect new nvarchar data type without
    having to rebuild entire Cube.
    SSAS 2005
     Thanks.

    Did you try to view the code on the Data Source view and cube that it is reflecting the correct data type on both places? if not you can change there and save it.
    prajwal kumar potula

Maybe you are looking for

  • Maximum number of character we can print in a column uing ALV grid display

    Hi frnds, My requirment is to print 500 charcter data in a column using ALV grid display. Could any body tell me is it possible and the maximum character it can i print in a column using ALV grid dispaly. Regards, Sandipan

  • Relation with parent components view with child component

    Hi All, Can a view controller of  one component can use his child component with the component usage declaration? Regards Chandra Edited by: Chandra Sekhara on Jan 4, 2008 4:26 AM

  • Simple query takes time to run

    Hi, I have a simple query whcih takes about 20 mins to run.. here is the TKPROF forit:   SELECT     SY2.QBAC0,     sum(decode(SALES_ORDER.SDCRCD,'USD', SALES_ORDER.SDAEXP,'CAD', SALES_ORDER.SDAEXP /1.0452))   FROM     JDE.F5542SY2  SY2,     JDE.F4211

  • Color calibration & Aperture suggestions?

    Working with Aperture, I am getting a wide variety of output from the various print shops I use for printing. My monitor is calibrated manually, but it is becoming apparent that this is no longer good enough and I am in need of a good calibrator. Fur

  • Can I Change Album Song Order Without Making a Playlist?

    Some albums get reissued in a different order than I am used to. To reorder the songs, I have been making a playlist and dragging the songs over in the order I want them. But--this feels like many extra steps. Can you just import the cd, and then reo