AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 01.07.2009, 00:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,644 / 848 (80) +++++++
Регистрация: 28.10.2006
SysDictCoder: Tricks with X++ embedded SQL
Источник: http://sysdictcoder.com/blog/tricks-...-embedded-sql/
==============
There are some tricks that you can do in X++ SQL. They’re not really well known because they’re not suited for normal use and there are not many clues in the editor that they exist. But they do come in handy every now and then.

Getting data without declaring a table variable
It’s possible to get data from the database without declaring any table variables. It goes something like this:
X++:
static void Job3(Args _args )   
{       
	// No variables!      
	;        

	print   (select CustTable).AccountNum;      
	pause;  
}
Note the parentheses around the select statement. This tells the compiler to create a temporary, anonymous buffer to hold the record. The select statement uses the exact table name and is immediately followed by a field name to get a value from a field.

If you use this there’s no Intellisense to help you look up the field name because the editor doesn’t know the type of the anonymous buffer.

This technique is often used in exist() methods on tables.

Getting a value from a field if you only know the field ID
Sometimes you don’t know the exact field name but you do know a field ID. Even in cases like this it’s possible to write an X++ SQL statement without knowing any field names.

Take a look at this example.
X++:
static void Job4(Args _args)   
{      
	CustTable   custTable;     
	FieldId     fieldId;     
	;       

	fieldId = fieldNum(CustTable, AccountNum);  // This could be passed as a method parameter         
	select custTable;  // Get first record         
	print custTable.(fieldId);  // Print account number         
	select custTable where custTable.(fieldId) == '1101' ;   // Where clause based on field ID         
	print custTable.Name;      
	pause;  
}
It’s possible to use field IDs to retrieve values as well as use them in a where clause. Again parentheses are the key. Instead of writing a regular field name, wrap the ID in parentheses and you’re done. This makes it possible create generic code to handle any table and field without knowing the types at compile time. If you dig around in the classes for importing and exporting data you’ll find some examples.

Источник: http://sysdictcoder.com/blog/tricks-...-embedded-sql/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Solutions Monkey: Convergence session: Enterprise Portal Deployment Tips and tricks Blog bot DAX Blogs 0 26.03.2009 08:05
Мир CRM: Улучшение Dynamics CRM 4.0 производительности и безопасности данных под SQL Server 2008 Blog bot Dynamics CRM: Blogs 0 03.02.2009 02:07
Мир CRM: Новости об одной из составляющих работы Dynamics CRM - Microsoft SQL Server Blog bot Dynamics CRM: Blogs 0 03.11.2008 06:18
Microsoft Dynamics CRM Team Blog: Accessing a SQL Database from a Microsoft Dynamics CRM Plug-in Blog bot Dynamics CRM: Blogs 0 14.07.2008 13:05
Dynamics AX: SQL Server, Heart of Dynamics AX Blog bot DAX Blogs 0 13.07.2007 18:00

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 03:59.