Read the field note on the table record link in sql server ?

PM53
Member Posts: 5
Hi,
I'm looking for read the field note on the table record link in sql server.
I have find how read the field record ID with that :
But I can't find how read the field note in sql ](*,)
Any ideas ?
Thank for your help
I'm looking for read the field note on the table record link in sql server.
I have find how read the field record ID with that :
SELECT CONVERT(varchar,substring([Record ID],8, LEN([Record ID]))) as 'ID',* FROM [Record Link]
But I can't find how read the field note in sql ](*,)
Any ideas ?
Thank for your help
0
Answers
-
Don't know if theres an easier way:
Make .Net Assembly that uses BinaryReader to Read the data and give it back as string. Register that assembly in SQL Server. Call the assembly.public class NAVNoteHandler { [SqlFunction(DataAccess = DataAccessKind.Read)] public static string GetNoteAsString(string NoteID) { try { using (SqlConnection connection = new SqlConnection("context connection=true")) { connection.Open(); SqlCommand command = new SqlCommand(string.Format("select [Note] FROM [Record Link] WHERE [Link ID] = {0}", NoteID), connection); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { SqlBytes bytes = reader.GetSqlBytes(0); MemoryStream ms = new MemoryStream(bytes.Value); BinaryReader BinReader = new BinaryReader(ms); return BinReader.ReadString(); } } return "null"; } catch (Exception ex) { return string.Empty; } } }
And here is a tutorial on how to register an assembly to sql server:
http://www.codeproject.com/KB/database/ ... n_SQL.aspx
Basicly you need call these T-SQL statements to Get a Result:exec sp_configure 'clr enabled',1 reconfigure go CREATE ASSEMBLY NAVNoteHandler AUTHORIZATION dbo FROM 'C:\sqldotnet\ClassLibrary1.dll' GO use [Demo Database NAV (6-0)] go CREATE FUNCTION usp_UseNAVNoteHandler ( @id as nvarchar(200) ) RETURNS nvarchar(200) AS EXTERNAL NAME NAVNoteHandler.[SQLProcedures.NAVNoteHandler].GetNoteAsString GO Select [Demo Database NAV (6-0)].[dbo].[usp_UseNAVNoteHandler]('1') as [Text]
IMPORTANT: You need to set the Property "Compressed" on the Note field in Table "Record Link" to false, otherwise you will get compressed output => nonsense0 -
When I try to execute this code :
use [NAVPROD311211] go CREATE FUNCTION usp_UseNAVNoteHandler ( @id as nvarchar(200) ) RETURNS nvarchar(200) AS EXTERNAL NAME NAVNoteHandler.[SQLProcedures.NAVNoteHandler].GetNoteAsString GO
I've this message :
Msg 6505,
The type 'SQLProcedures.NAVNoteHandler' is not found in the assembly 'ClassLibrary1'.
Nevertheless I see my assembly in my database -> Assembly -> NAVNoteHandler
My NavNoteHandler.cs :using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SqlServer.Server; using System.Data.SqlClient; using System.IO; using System.Data.SqlTypes; namespace ClassLibrary1 { public class NAVNoteHandler { [SqlFunction(DataAccess = DataAccessKind.Read)] public static string GetNoteAsString(string NoteID) { try { using (SqlConnection connection = new SqlConnection("context connection=true")) { connection.Open(); SqlCommand command = new SqlCommand(string.Format("select [Note] FROM [Record Link] WHERE [Link ID] = {0}", NoteID), connection); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { SqlBytes bytes = reader.GetSqlBytes(0); MemoryStream ms = new MemoryStream(bytes.Value); BinaryReader BinReader = new BinaryReader(ms); return BinReader.ReadString(); } } return "null"; } catch (Exception ex) { return string.Empty; } } } }
Where is the error ?
Thanks for you help
I'm sorry for my English, I'm French...0 -
Ok, it works but I can't to find the property "Compressed" on the "Note" field...
Where are you going for to find this property ?
I use SQL Server 2008 x64 / Nav 2009 SP1 RTC
Screenshot
Thanks for your help0 -
Ok, nice it works !!!
Thank you very much. =D> =D>
Good day0 -
Hi,
after setting the field property "compressed" to NO, some client (RTC) for some users only crashed. Any idea?
thanx a lot
regards
CHris#### Only one can survive ######0 -
I tried to follow the instructions and I created the assembly and the SQL-function.
However when I run the function it only shows 'D' as a result for every record from the [Record Link] table.
What am I doing wrong?0 -
Hi, I have copied and checked your script. It runs but all notes return "D". What have I done wrong? How can I fix? Thanks for your help.0
-
I followed this and was able to get it to work, however after I did the step to set the Note field as Uncompressed in NAV, I was then able to simply return the note content by casting the image type Note field to varbinary and then varchar:
select cast(cast(Note as varbinary(max)) as varchar(max)) from [Record Link]
So people may find that easier or more convenient if they're trying to return Note content in SQL.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions