Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Adding a Macro in SQL View modes: 
User avatar
Member
Member
usmaan.dad-controlf1.co - 6/13/2013 3:23:29 AM
   
Adding a Macro in SQL
Hi Forum,

I wish to add a macro in my sql so that I can do something like this:

dc1.DocumentID = {%DocumentID%}

Basically meaning, where the DocumentID of dc1 is Equal to the current DocumentID.

Any idea how I can achieve this?

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 6/13/2013 8:48:17 AM
   
RE:Adding a Macro in SQL
Why do it in your SQL? If you have created a custom query for a document type, simply add the ##WHERE## tag and in your listing web part simply fill out the Where property
DocumentID={%DocumentID%}

User avatar
Member
Member
usmaan.dad-controlf1.co - 6/13/2013 10:28:09 AM
   
RE:Adding a Macro in SQL
Okay. I have placed a #WHERE## tag in the SQL section and in the Where text box, I am trying to do this:

NodeParentNodeID = {% NodeID %} or NodeAliasPath LIKE ' {% NodeAliasPath + /Featured/%' %}

I have the macro symbols jumbled up. How can I syntactically get the above working?

User avatar
Kentico Legend
Kentico Legend
Accepted solutionAccepted solution
Brenden Kehren - 6/13/2013 10:37:43 AM
   
RE:Adding a Macro in SQL
I believe what you are looking for would be
NodeParentNodeID = {% NodeID %} or NodeAliasPath LIKE ' {% NodeAliasPath %}/Featured/%'
If you put single quotes in a macro to connect a string, the macro will escape it (for SQL injection reasons).  So only put the item in you need in the macro and add the rest outside of the macro.

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 6/13/2013 10:38:23 AM
   
RE:Adding a Macro in SQL
Oops, bad form on my end, forgot to close the code block properly.

User avatar
Member
Member
Swainy - 6/13/2013 8:48:24 AM
   
RE:Adding a Macro in SQL
Hi Usmann,

Cna you explain in what context you are trying to do this?

If you are in code then you can use CMSContext.CurrentDocument.DocumentID to get the document ID of the current document.

I would always encourage using the Kentico API to get data in and out of the database rather than writing your own SQL.

If you need any further help let me know,

Thanks,

Matt

User avatar
Member
Member
usmaan.dad-controlf1.co - 6/13/2013 10:30:39 AM
   
RE:Adding a Macro in SQL
Hi Matt,

I am trying to do this in a Repeater With Custom Query web part.

I have added a ##WHERE## tag in the SQL section and in the Where TextBox I have added:

NodeParentNodeID NodeID %} or NodeAliasPath LIKE ' {% NodeAliasPath + /Featured/% %} '

Which is incorrect as I believe the macro symbols are jumbled up. How can I make the above syntactically correct?

User avatar
Kentico Support
Kentico Support
Accepted solutionAccepted solution
kentico_jurajo - 6/13/2013 10:58:34 AM
   
RE:Adding a Macro in SQL
Hi,

Yes, your syntax is not correct. The example below just shows you the syntax as I do not know what exactly you want to do, it may not work as you want :-)

WHERE:
NodeParentID = {%NodeID%} OR NodeAliasPath LIKE '{%NodeAliasPath%}/Featured/%'


Best regards,
Juraj Ondrus

User avatar
Member
Member
usmaan - 6/20/2013 10:20:05 AM
   
RE:Adding a Macro in SQL
Thank you very much Juraj. That's exactly what I needed. +1 to you and FroggEye.