<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4397571491774519607</id><updated>2012-01-17T14:25:05.971-08:00</updated><category term='SQL Server 2005'/><category term='meta-data utility'/><title type='text'>David Korb's SQL weblog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://sprocking.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4397571491774519607/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://sprocking.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>David</name><uri>http://www.blogger.com/profile/05948936335943076933</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='21' src='http://2.bp.blogspot.com/-xlxjycf5EQA/TxXywpCw0lI/AAAAAAAAAAQ/ryWziFxNTnQ/s220/Cats_Eye_Nebula_NGC_6543.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4397571491774519607.post-1396858260300670639</id><published>2010-08-03T13:39:00.000-07:00</published><updated>2010-08-03T13:54:20.917-07:00</updated><title type='text'>SAS date in a pass-through query</title><content type='html'>Dates have to be passed into Teradata as quoted strings and you can't just concatenate single quotes to the macro variable using the native RDBMS syntax. What you need is the %BQUOTE function to mask a quote as you assign it to a macro variable. Here is an example where you want the last 5 days of data.&lt;br /&gt;&lt;br /&gt;data _null_;&lt;br /&gt;    call symput( 'ystrdt', put(date() - 5, yymmdd10.) );&lt;br /&gt;run;&lt;br /&gt;&lt;br /&gt;%let q=%BQUOTE(');&lt;br /&gt;&lt;br /&gt;PROC SQL;&lt;br /&gt;        CONNECT TO TERADATA (connection information);&lt;br /&gt;        EXEC(COMMIT) BY TERADATA;&lt;br /&gt;&lt;br /&gt;        EXEC&lt;br /&gt;        (&lt;br /&gt;                INSERT INTO db_name.test_table&lt;br /&gt;                SELECT ...some_list...&lt;br /&gt;                FROM db_name.some_table&lt;br /&gt;                WHERE some_date &gt; &amp;q&amp;ystrdt&amp;q&lt;br /&gt;        ) BY TERADATA;&lt;br /&gt;        EXEC(COMMIT) BY TERADATA;&lt;br /&gt;&lt;br /&gt;        DISCONNECT FROM TERADATA;&lt;br /&gt;QUIT;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4397571491774519607-1396858260300670639?l=sprocking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sprocking.blogspot.com/feeds/1396858260300670639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sprocking.blogspot.com/2010/08/sas-date-in-pass-through-query.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4397571491774519607/posts/default/1396858260300670639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4397571491774519607/posts/default/1396858260300670639'/><link rel='alternate' type='text/html' href='http://sprocking.blogspot.com/2010/08/sas-date-in-pass-through-query.html' title='SAS date in a pass-through query'/><author><name>David</name><uri>http://www.blogger.com/profile/05948936335943076933</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='21' src='http://2.bp.blogspot.com/-xlxjycf5EQA/TxXywpCw0lI/AAAAAAAAAAQ/ryWziFxNTnQ/s220/Cats_Eye_Nebula_NGC_6543.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4397571491774519607.post-1387870949761265191</id><published>2010-02-16T09:03:00.000-08:00</published><updated>2010-02-16T09:35:29.542-08:00</updated><title type='text'>Variables in Teradata</title><content type='html'>As of this writing, I am managing batch scripts that hit Teradata servers. Unlike MS SQL Server, Teradata does not allow functionality such as branching logic or variables. Unfortunately, this means the programmer has to bend over backwards to get work done and the code becomes less readable.&lt;br /&gt;&lt;br /&gt;For this example, what would be a simple date variable is replaced with a volatile table containing a date. This allows dynamic filtering so that the programmer does not have to edit the script on a daily basis.&lt;br /&gt;&lt;br /&gt;-- Create the temp table.&lt;br /&gt;CREATE VOLATILE TABLE process_date (&lt;br /&gt; batch_date DATE  NOT NULL FORMAT 'yyyy-mm-dd'&lt;br /&gt;)&lt;br /&gt;UNIQUE PRIMARY INDEX (batch_date)&lt;br /&gt;   ON&lt;br /&gt;COMMIT&lt;br /&gt;PRESERVE  ROWS;&lt;br /&gt;&lt;br /&gt;-- Insert a value.&lt;br /&gt;INSERT INTO process_date( batch_date )&lt;br /&gt;SELECT DATE;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- Query the previous 90 days of data using the date filter.&lt;br /&gt;SELECT  tbl.field_name&lt;br /&gt;FROM database_name.table_name AS tbl&lt;br /&gt;WHERE EXISTS (&lt;br /&gt; SELECT *&lt;br /&gt; FROM process_date AS PDT&lt;br /&gt; WHERE tbl.date_name&lt;br /&gt;  BETWEEN PDT.batch_date - 90 AND PDT.batch_date - 1&lt;br /&gt;);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4397571491774519607-1387870949761265191?l=sprocking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sprocking.blogspot.com/feeds/1387870949761265191/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sprocking.blogspot.com/2010/02/variables-in-teradata.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4397571491774519607/posts/default/1387870949761265191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4397571491774519607/posts/default/1387870949761265191'/><link rel='alternate' type='text/html' href='http://sprocking.blogspot.com/2010/02/variables-in-teradata.html' title='Variables in Teradata'/><author><name>David</name><uri>http://www.blogger.com/profile/05948936335943076933</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='21' src='http://2.bp.blogspot.com/-xlxjycf5EQA/TxXywpCw0lI/AAAAAAAAAAQ/ryWziFxNTnQ/s220/Cats_Eye_Nebula_NGC_6543.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4397571491774519607.post-8555105149242316553</id><published>2009-08-17T10:35:00.001-07:00</published><updated>2009-08-17T10:38:32.814-07:00</updated><title type='text'>Create a tally table using a CTE</title><content type='html'>create table dbo.t_tally (&lt;br /&gt;   i int not null&lt;br /&gt;   ,constraint pk_t_tally primary key clustered (i)&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;;with digits (i) as(&lt;br /&gt;   select 1 as i union all  select 2 as i union all select 3 union all&lt;br /&gt;   select 4 union all select 5 union all select 6 union all select 7 union all&lt;br /&gt;   select 8 union all select 9 union all select 0)&lt;br /&gt;   ,sequence(i) as (&lt;br /&gt;select&lt;br /&gt;   d1.i&lt;br /&gt;   + (10*d2.i)&lt;br /&gt;   + (100*d3.i)&lt;br /&gt;   + (1000*d4.i)&lt;br /&gt;   + (10000*d5.i)&lt;br /&gt;from digits as d1&lt;br /&gt;   ,digits as d2&lt;br /&gt;   ,digits as d3&lt;br /&gt;   ,digits as d4&lt;br /&gt;       ,digits as d5&lt;br /&gt;)&lt;br /&gt;insert into dbo.t_tally&lt;br /&gt;select i&lt;br /&gt;from sequence&lt;br /&gt;where i &lt; 65537&lt;br /&gt;order by i&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4397571491774519607-8555105149242316553?l=sprocking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://sprocking.blogspot.com/feeds/8555105149242316553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sprocking.blogspot.com/2009/08/create-tally-table-with-cte.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4397571491774519607/posts/default/8555105149242316553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4397571491774519607/posts/default/8555105149242316553'/><link rel='alternate' type='text/html' href='http://sprocking.blogspot.com/2009/08/create-tally-table-with-cte.html' title='Create a tally table using a CTE'/><author><name>David</name><uri>http://www.blogger.com/profile/05948936335943076933</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='21' src='http://2.bp.blogspot.com/-xlxjycf5EQA/TxXywpCw0lI/AAAAAAAAAAQ/ryWziFxNTnQ/s220/Cats_Eye_Nebula_NGC_6543.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4397571491774519607.post-692763316539555083</id><published>2009-08-13T19:43:00.000-07:00</published><updated>2009-08-13T22:22:36.149-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL Server 2005'/><category scheme='http://www.blogger.com/atom/ns#' term='meta-data utility'/><title type='text'>SQL Server 2005 string search utility</title><content type='html'>A utility for finding strings in compiled objects on an instance of SQL Server 2005. Compiled objects being: user-defined functions, stored procedures, triggers, views, check constraints.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4397571491774519607-692763316539555083?l=sprocking.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='related' href='http://www.sqlservercentral.com/scripts/Search/64839/' title='SQL Server 2005 string search utility'/><link rel='replies' type='application/atom+xml' href='http://sprocking.blogspot.com/feeds/692763316539555083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://sprocking.blogspot.com/2009/08/test.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4397571491774519607/posts/default/692763316539555083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4397571491774519607/posts/default/692763316539555083'/><link rel='alternate' type='text/html' href='http://sprocking.blogspot.com/2009/08/test.html' title='SQL Server 2005 string search utility'/><author><name>David</name><uri>http://www.blogger.com/profile/05948936335943076933</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='33' height='21' src='http://2.bp.blogspot.com/-xlxjycf5EQA/TxXywpCw0lI/AAAAAAAAAAQ/ryWziFxNTnQ/s220/Cats_Eye_Nebula_NGC_6543.jpg'/></author><thr:total>1</thr:total></entry></feed>
