Monday, March 19, 2012
Can NEWLINE in FORMAT?
The output is: Fri 10/15/04
I would like this instead:
Fri
10/15/04
Is there a way to add a line break using the simple format codes?
Thanks, JerryI have found that adding
... & chr(10) & chr(13) & ...
seems to do the trick.
"Jerry Nixon" wrote:
> I have a date field and use the format: dd MM/dd/yy
> The output is: Fri 10/15/04
> I would like this instead:
> Fri
> 10/15/04
> Is there a way to add a line break using the simple format codes?
> Thanks, Jerry
>|||I do not know of a way that you can add a line break when typing the format
code into the Format property. It can be done in several ways when using an
expression. For example:
=Format( Fields!YoureDate.Value, "ddd") + ControlChars.crlf + Format(
Fields!YourDate.Value, "MM/dd/yy")
"Jerry Nixon" wrote:
> I have a date field and use the format: dd MM/dd/yy
> The output is: Fri 10/15/04
> I would like this instead:
> Fri
> 10/15/04
> Is there a way to add a line break using the simple format codes?
> Thanks, Jerry
>
Thursday, March 8, 2012
can I use the value of field in last record?
I handle a output by a function with three parameters
the first is a value of Field [a1] in current record,
the second is value of Field [a1] in last record,
the third is value of Field [a1] in next record,
is it possible in RS2005?
Yes you can use them in a given scope (table/list):
Fields!a1.Value
Last(Fields!a1.Value, "Dataset1")
Fields!a1.Value(RowNumber("Dataset1")+1)
Shyam
Saturday, February 25, 2012
Can I use a table variable in sp_executesql for output
Example:
Normally I might have something like:
DECLARE @.max varchar(9),@.sExec nvarchar(200)
SELECT @.sExec=N'SELECT @.max=(SELECT MAX(ID) FROM Parts)'
EXEC sp_executesql @.sExec, N'@.max varchar(9) OUTPUT', @.max OUTPUT
print @.max
--I'm doing something wrong... what?
--Instead can it be written to work like this?
DECLARE @.tmp TABLE(@.max varchar(9)null)
DECLARE @.sExec nvarchar(200)
SELECT @.sExec=N'INSERT INTO @.tmp =(SELECT Convert(varchar(9),ID) FROM Parts)'
N'@.tmp TABLE(@.max varchar(9)null) OUTPUT', @.tmp OUTPUT
SELECT Max(ID) FROM @.tmp
Regards,
Jamie
No but you can create a temp table before you call the sp_executesql and
access it from inside the dynamic sql. Those rows that you insert inside
the dynamic sql will still be there after the sp_executesql batch is done.
Andrew J. Kelly SQL MVP
"thejamie" <thejamie@.discussions.microsoft.com> wrote in message
news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
> Can I use a table variable to gain output using the sp_executesql
> procedure?
> Example:
> Normally I might have something like:
> DECLARE @.max varchar(9),@.sExec nvarchar(200)
> SELECT @.sExec=N'SELECT @.max=(SELECT MAX(ID) FROM Parts)'
> EXEC sp_executesql @.sExec, N'@.max varchar(9) OUTPUT', @.max OUTPUT
> print @.max
> --I'm doing something wrong... what?
> --Instead can it be written to work like this?
> DECLARE @.tmp TABLE(@.max varchar(9)null)
> DECLARE @.sExec nvarchar(200)
> SELECT @.sExec=N'INSERT INTO @.tmp =(SELECT Convert(varchar(9),ID) FROM
> Parts)'
> N'@.tmp TABLE(@.max varchar(9)null) OUTPUT', @.tmp OUTPUT
> SELECT Max(ID) FROM @.tmp
> Regards,
> Jamie
|||Andrew,
Thanks for replying.
I am trying to get percentages of a single table for weighting.
If I understand right, then this should work for my first 60 percent of the
table.
DECLARE @.PercA varchar(2)
SELECT @.PercA='60'
DECLARE @.ITEMZ1 TABLE(item_no varchar(30))
SELECT @.SQL=N'(INSERT INTO @.ITEMZ1 SELECT TOP '+@.A+N' PERCENT L.item_no FROM
iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND L.item_no =
N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC)'
EXEC sp_executesql @.SQL, N'@.ITEMZ1 TABLE(item_no varchar(30)) OUTPUT',
@.ITEMZ1 OUTPUT
SELECT * FROM @.ITEMZ1
I'm missing something. Is it obvious?
Jamie
"Andrew J. Kelly" wrote:
> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
>
>
|||I found something similar - says it works in YUKON only.
http://www.c-sharpcorner.com/Longhor...ordInYukon.asp
This is what I really want. Is there a way to do this pre-YUKON?
DECLARE @.n AS int
SET @.n = 60
SELECT TOP(@.n)
L.item_no FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc
AND L.item_no = N.item_no
ORDER BY L.avg_cost * L.usage_ytd DESC
"Andrew J. Kelly" wrote:
> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
>
>
|||Suppose the tmptable needed to be created from a string variable fed into the
stored procedure:
The last line below does not work, but follows the same logic. Can a temp
table be created from an EXEC (@.SQL) statement?
DECLARE @.SQL nvarchar(4000),@.BeginPercent tinyint,@.EndPercent
tinyint,@.SQLLength int,@.FieldList varchar(4000),@.SQLTmpTbl
nvarchar(4000),@.ComputedField varchar(128)
SELECT @.SQL=N'SELECT
L.item_no,N.item_desc_1,N.item_desc_2,L.usage_ytd, L.avg_cost,L.inv_class,L.loc,L.prod_cat
FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND L.item_no
= N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC'
SELECT @.ComputedField=N'L.usage_ytd * L.avg_cost'
DECLARE @.SQLSelect nvarchar(4000),@.SQLFROM nvarchar(4000)
SELECT @.SQLSelect=dbo.instr(@.SQL,'FROM')
SELECT @.SQLFROM=REPLACE(@.SQL,@.SQLSelect,'')
SELECT @.FieldList=LTRIM(RTRIM(REPLACE(@.SQLSelect,'SELECT' ,'')))
SELECT @.FieldList=REPLACE(@.FieldList,',',' varchar(255),')
SELECT @.FieldList=@.FieldList+' nvarchar(255)'
SELECT @.SQLTmpTbl=N'DECLARE @.tmp TABLE('+@.Fieldlist+N')'
Print REPLACE(@.SQLTmpTbl,'.','_')
exec sp_executesql @.SQLTmpTbl
"Andrew J. Kelly" wrote:
> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>
|||First of all that is a table variable and not a temp table. But in either
case it will not work as you expect. The scoping of variables and temp
tables that are created inside dynamic sql are limited to that execution
only. Once they are done the code outside of that dynamic batch will not
see those objects. Only if you create a temp table (not a table var)
outside of the dynamic sql batch will it be usable in the batch and then
again after the batch. Have a look at these:
http://www.aspfaq.com/show.asp?id=2248 Arrays & Lists
http://www.sommarskog.se/dynamic_sql.html Dynamic SQL
http://www.users.drew.edu/skass/sql/...leProc.sql.txt List to
Table script
http://www.support.microsoft.com/?id=262499 Using OutPut Params &
sp_executeSql
Andrew J. Kelly SQL MVP
"thejamie" <thejamie@.discussions.microsoft.com> wrote in message
news:BE8B9EC0-7CD2-4E71-BA09-C966895456D8@.microsoft.com...[vbcol=seagreen]
> Suppose the tmptable needed to be created from a string variable fed into
> the
> stored procedure:
> The last line below does not work, but follows the same logic. Can a
> temp
> table be created from an EXEC (@.SQL) statement?
> DECLARE @.SQL nvarchar(4000),@.BeginPercent tinyint,@.EndPercent
> tinyint,@.SQLLength int,@.FieldList varchar(4000),@.SQLTmpTbl
> nvarchar(4000),@.ComputedField varchar(128)
> SELECT @.SQL=N'SELECT
> L.item_no,N.item_desc_1,N.item_desc_2,L.usage_ytd, L.avg_cost,L.inv_class,L.loc,L.prod_cat
> FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND
> L.item_no
> = N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC'
> SELECT @.ComputedField=N'L.usage_ytd * L.avg_cost'
> DECLARE @.SQLSelect nvarchar(4000),@.SQLFROM nvarchar(4000)
> SELECT @.SQLSelect=dbo.instr(@.SQL,'FROM')
> SELECT @.SQLFROM=REPLACE(@.SQL,@.SQLSelect,'')
> SELECT @.FieldList=LTRIM(RTRIM(REPLACE(@.SQLSelect,'SELECT' ,'')))
> SELECT @.FieldList=REPLACE(@.FieldList,',',' varchar(255),')
> SELECT @.FieldList=@.FieldList+' nvarchar(255)'
> SELECT @.SQLTmpTbl=N'DECLARE @.tmp TABLE('+@.Fieldlist+N')'
> Print REPLACE(@.SQLTmpTbl,'.','_')
> exec sp_executesql @.SQLTmpTbl
>
> "Andrew J. Kelly" wrote:
|||That worked quite well. Thank you Andrew
"Andrew J. Kelly" wrote:
> First of all that is a table variable and not a temp table. But in either
> case it will not work as you expect. The scoping of variables and temp
> tables that are created inside dynamic sql are limited to that execution
> only. Once they are done the code outside of that dynamic batch will not
> see those objects. Only if you create a temp table (not a table var)
> outside of the dynamic sql batch will it be usable in the batch and then
> again after the batch. Have a look at these:
>
> http://www.aspfaq.com/show.asp?id=2248 Arrays & Lists
> http://www.sommarskog.se/dynamic_sql.html Dynamic SQL
> http://www.users.drew.edu/skass/sql/...leProc.sql.txt List to
> Table script
> http://www.support.microsoft.com/?id=262499 Using OutPut Params &
> sp_executeSql
>
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:BE8B9EC0-7CD2-4E71-BA09-C966895456D8@.microsoft.com...
>
>
Can I use a table variable in sp_executesql for output
Example:
Normally I might have something like:
DECLARE @.max varchar(9),@.sExec nvarchar(200)
SELECT @.sExec=N'SELECT @.max=(SELECT MAX(ID) FROM Parts)'
EXEC sp_executesql @.sExec, N'@.max varchar(9) OUTPUT', @.max OUTPUT
print @.max
--I'm doing something wrong... what?
--Instead can it be written to work like this?
DECLARE @.tmp TABLE(@.max varchar(9)null)
DECLARE @.sExec nvarchar(200)
SELECT @.sExec=N'INSERT INTO @.tmp =(SELECT Convert(varchar(9),ID) FROM Parts)
'
N'@.tmp TABLE(@.max varchar(9)null) OUTPUT', @.tmp OUTPUT
SELECT Max(ID) FROM @.tmp
Regards,
JamieNo but you can create a temp table before you call the sp_executesql and
access it from inside the dynamic sql. Those rows that you insert inside
the dynamic sql will still be there after the sp_executesql batch is done.
Andrew J. Kelly SQL MVP
"thejamie" <thejamie@.discussions.microsoft.com> wrote in message
news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
> Can I use a table variable to gain output using the sp_executesql
> procedure?
> Example:
> Normally I might have something like:
> DECLARE @.max varchar(9),@.sExec nvarchar(200)
> SELECT @.sExec=N'SELECT @.max=(SELECT MAX(ID) FROM Parts)'
> EXEC sp_executesql @.sExec, N'@.max varchar(9) OUTPUT', @.max OUTPUT
> print @.max
> --I'm doing something wrong... what?
> --Instead can it be written to work like this?
> DECLARE @.tmp TABLE(@.max varchar(9)null)
> DECLARE @.sExec nvarchar(200)
> SELECT @.sExec=N'INSERT INTO @.tmp =(SELECT Convert(varchar(9),ID) FROM
> Parts)'
> N'@.tmp TABLE(@.max varchar(9)null) OUTPUT', @.tmp OUTPUT
> SELECT Max(ID) FROM @.tmp
> Regards,
> Jamie|||Andrew,
Thanks for replying.
I am trying to get percentages of a single table for weighting.
If I understand right, then this should work for my first 60 percent of the
table.
DECLARE @.PercA varchar(2)
SELECT @.PercA='60'
DECLARE @.ITEMZ1 TABLE(item_no varchar(30))
SELECT @.SQL=N'(INSERT INTO @.ITEMZ1 SELECT TOP '+@.A+N' PERCENT L.item_no FROM
iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND L.item_no =
N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC)'
EXEC sp_executesql @.SQL, N'@.ITEMZ1 TABLE(item_no varchar(30)) OUTPUT',
@.ITEMZ1 OUTPUT
SELECT * FROM @.ITEMZ1
I'm missing something. Is it obvious?
Jamie
"Andrew J. Kelly" wrote:
> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
>
>|||I found something similar - says it works in YUKON only.
http://www.c-sharpcorner.com/Longho...wordInYukon.asp
This is what I really want. Is there a way to do this pre-YUKON?
DECLARE @.n AS int
SET @.n = 60
SELECT TOP(@.n)
L.item_no FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc
AND L.item_no = N.item_no
ORDER BY L.avg_cost * L.usage_ytd DESC
"Andrew J. Kelly" wrote:
> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:99D6CE2F-9252-4AB9-A690-8CF00420926C@.microsoft.com...
>
>|||Suppose the tmptable needed to be created from a string variable fed into th
e
stored procedure:
The last line below does not work, but follows the same logic. Can a temp
table be created from an EXEC (@.SQL) statement?
DECLARE @.SQL nvarchar(4000),@.BeginPercent tinyint,@.EndPercent
tinyint,@.SQLLength int,@.FieldList varchar(4000),@.SQLTmpTbl
nvarchar(4000),@.ComputedField varchar(128)
SELECT @.SQL=N'SELECT
L.item_no,N.item_desc_1,N.item_desc_2,L.usage_ytd,L.avg_cost,L.inv_class,L.l
oc,L.prod_cat
FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND L.item_no
= N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC'
SELECT @.ComputedField=N'L.usage_ytd * L.avg_cost'
DECLARE @.SQLSelect nvarchar(4000),@.SQLFROM nvarchar(4000)
SELECT @.SQLSelect=dbo.instr(@.SQL,'FROM')
SELECT @.SQLFROM=REPLACE(@.SQL,@.SQLSelect,'')
SELECT @.FieldList=LTRIM(RTRIM(REPLACE(@.SQLSelec
t,'SELECT','')))
SELECT @.FieldList=REPLACE(@.FieldList,',',' varchar(255),')
SELECT @.FieldList=@.FieldList+' nvarchar(255)'
SELECT @.SQLTmpTbl=N'DECLARE @.tmp TABLE('+@.Fieldlist+N')'
Print REPLACE(@.SQLTmpTbl,'.','_')
exec sp_executesql @.SQLTmpTbl
"Andrew J. Kelly" wrote:
> No but you can create a temp table before you call the sp_executesql and
> access it from inside the dynamic sql. Those rows that you insert inside
> the dynamic sql will still be there after the sp_executesql batch is done.
> --
> Andrew J. Kelly SQL MVP
>|||First of all that is a table variable and not a temp table. But in either
case it will not work as you expect. The scoping of variables and temp
tables that are created inside dynamic sql are limited to that execution
only. Once they are done the code outside of that dynamic batch will not
see those objects. Only if you create a temp table (not a table var)
outside of the dynamic sql batch will it be usable in the batch and then
again after the batch. Have a look at these:
http://www.aspfaq.com/show.asp?id=2248 Arrays & Lists
http://www.sommarskog.se/dynamic_sql.html Dynamic SQL
http://www.users.drew.edu/skass/sql...bleProc.sql.txt List to
Table script
http://www.support.microsoft.com/?id=262499 Using OutPut Params &
sp_executeSql
Andrew J. Kelly SQL MVP
"thejamie" <thejamie@.discussions.microsoft.com> wrote in message
news:BE8B9EC0-7CD2-4E71-BA09-C966895456D8@.microsoft.com...[vbcol=seagreen]
> Suppose the tmptable needed to be created from a string variable fed into
> the
> stored procedure:
> The last line below does not work, but follows the same logic. Can a
> temp
> table be created from an EXEC (@.SQL) statement?
> DECLARE @.SQL nvarchar(4000),@.BeginPercent tinyint,@.EndPercent
> tinyint,@.SQLLength int,@.FieldList varchar(4000),@.SQLTmpTbl
> nvarchar(4000),@.ComputedField varchar(128)
> SELECT @.SQL=N'SELECT
> L.item_no,N.item_desc_1,N.item_desc_2,L.usage_ytd,L.avg_cost,L.inv_class,L
.loc,L.prod_cat
> FROM iminvloc_sql L INNER JOIN imitmidx_sql N ON L.loc = N.loc AND
> L.item_no
> = N.item_no ORDER BY L.avg_cost * L.usage_ytd DESC'
> SELECT @.ComputedField=N'L.usage_ytd * L.avg_cost'
> DECLARE @.SQLSelect nvarchar(4000),@.SQLFROM nvarchar(4000)
> SELECT @.SQLSelect=dbo.instr(@.SQL,'FROM')
> SELECT @.SQLFROM=REPLACE(@.SQL,@.SQLSelect,'')
> SELECT @.FieldList=LTRIM(RTRIM(REPLACE(@.SQLSelec
t,'SELECT','')))
> SELECT @.FieldList=REPLACE(@.FieldList,',',' varchar(255),')
> SELECT @.FieldList=@.FieldList+' nvarchar(255)'
> SELECT @.SQLTmpTbl=N'DECLARE @.tmp TABLE('+@.Fieldlist+N')'
> Print REPLACE(@.SQLTmpTbl,'.','_')
> exec sp_executesql @.SQLTmpTbl
>
> "Andrew J. Kelly" wrote:
>|||That worked quite well. Thank you Andrew
"Andrew J. Kelly" wrote:
> First of all that is a table variable and not a temp table. But in either
> case it will not work as you expect. The scoping of variables and temp
> tables that are created inside dynamic sql are limited to that execution
> only. Once they are done the code outside of that dynamic batch will not
> see those objects. Only if you create a temp table (not a table var)
> outside of the dynamic sql batch will it be usable in the batch and then
> again after the batch. Have a look at these:
>
> http://www.aspfaq.com/show.asp?id=2248 Arrays & Lists
> http://www.sommarskog.se/dynamic_sql.html Dynamic SQL
> http://www.users.drew.edu/skass/sql...bleProc.sql.txt List to
> Table script
> http://www.support.microsoft.com/?id=262499 Using OutPut Params &
> sp_executeSql
>
> --
> Andrew J. Kelly SQL MVP
>
> "thejamie" <thejamie@.discussions.microsoft.com> wrote in message
> news:BE8B9EC0-7CD2-4E71-BA09-C966895456D8@.microsoft.com...
>
>
Friday, February 24, 2012
can I use * to specify 'Output Column' for OLD DB Source Editor?
I am working on a situation similar to 'Get all from Table A that isn't in Table B' http://www.sqlis.com/default.aspx?311
I noticed that if one column's name of source table changes,(say Year to Year2) I have to modify all 'data flow transformations' in the task.
I am new to SSIS.
thanks! -ZZ
ZZhang wrote:
I am working on a situation similar to 'Get all from Table A that isn't in Table B' http://www.sqlis.com/default.aspx?311
I noticed that if one column's name of source table changes,(say Year to Year2) I have to modify all 'data flow transformations' in the task.
I am new to SSIS.
thanks! -ZZ
You could use '*' if you wanted but this is about as bad as bad practice gets. Don't do it. If the name of a column changes then SSIS will break because it stored the metadata of the external data source. This is by design.
-Jamie
|||
Hi, Jamie,
Thanks so much for your quick response! I have two questions then.
1. How to use * ? I can not find it in the 'OLD DB Source Editor'.
2. Let me simplifing my case. I have a remote source table ( which has may columns, incluing 'ID' and 'Date'). The schema may change, but not 'ID' and 'Date' columns. The DTS job is to get all rows ( select * from myTable where [Date] = getdate() ), and output to a delimited flat file.
What is the best practice SSIS for this case?
Thanks again!
-ZZ
|||Like I said. You can't do it. If the external metadata changes then your data-flow will error.
-Jamie
|||
thanks, Jamie!
Honestly, this surprised me, if it can not use *. I will choose NOT to use SSIS for my simple job, because it does not make sense to modify ( and test) SSIS package every time the schema changes. I hope there is a workaround to meet my job requirement in SSIS.
-ZZ
|||What? Your problem is the fact that your schema is changing, not that SSIS can't handle it. Are you saying that its impossible to know what your schema will look like from one day to the next? I've never seen a company that would run its systems like that nor would i want to.
Sorry to sound rude but it just sounds crazy to me!
-Jamie
|||
Thanks Jamie for your time to answer my question!
I am new to SSIS, and have not used variable, expression, and sricpt much. I am open-mind, and believe there is a way (simple or difficult), to solve my issue. Maybe you are right, but here I am searching 'how-to' solution, like ( select * from MyTable). Should I use *? it is another question.
Thanks again!
-ZZhang
|||Again,
Yes you can use "SELECT * FROM MyTable"|||
It seems that MS has solution for 'Dynamic Metadata', although SSIS pipeline requires static metadata.
"Advacned ETL: Embedding Integration Services" from PDC05 mentioned this issue. SMO is needed.
I am still searching for the samples.
-ZZhang
can I use * to specify 'Output Column' for OLD DB Source Editor?
I am working on a situation similar to 'Get all from Table A that isn't in Table B' http://www.sqlis.com/default.aspx?311
I noticed that if one column's name of source table changes,(say Year to Year2) I have to modify all 'data flow transformations' in the task.
I am new to SSIS.
thanks! -ZZ
ZZhang wrote:
I am working on a situation similar to 'Get all from Table A that isn't in Table B' http://www.sqlis.com/default.aspx?311
I noticed that if one column's name of source table changes,(say Year to Year2) I have to modify all 'data flow transformations' in the task.
I am new to SSIS.
thanks! -ZZ
You could use '*' if you wanted but this is about as bad as bad practice gets. Don't do it. If the name of a column changes then SSIS will break because it stored the metadata of the external data source. This is by design.
-Jamie
|||
Hi, Jamie,
Thanks so much for your quick response! I have two questions then.
1. How to use * ? I can not find it in the 'OLD DB Source Editor'.
2. Let me simplifing my case. I have a remote source table ( which has may columns, incluing 'ID' and 'Date'). The schema may change, but not 'ID' and 'Date' columns. The DTS job is to get all rows ( select * from myTable where [Date] = getdate() ), and output to a delimited flat file.
What is the best practice SSIS for this case?
Thanks again!
-ZZ
|||Like I said. You can't do it. If the external metadata changes then your data-flow will error.
-Jamie
|||
thanks, Jamie!
Honestly, this surprised me, if it can not use *. I will choose NOT to use SSIS for my simple job, because it does not make sense to modify ( and test) SSIS package every time the schema changes. I hope there is a workaround to meet my job requirement in SSIS.
-ZZ
|||What? Your problem is the fact that your schema is changing, not that SSIS can't handle it. Are you saying that its impossible to know what your schema will look like from one day to the next? I've never seen a company that would run its systems like that nor would i want to.
Sorry to sound rude but it just sounds crazy to me!
-Jamie
|||
Thanks Jamie for your time to answer my question!
I am new to SSIS, and have not used variable, expression, and sricpt much. I am open-mind, and believe there is a way (simple or difficult), to solve my issue. Maybe you are right, but here I am searching 'how-to' solution, like ( select * from MyTable). Should I use *? it is another question.
Thanks again!
-ZZhang
|||Again,
Yes you can use "SELECT * FROM MyTable"|||
It seems that MS has solution for 'Dynamic Metadata', although SSIS pipeline requires static metadata.
"Advacned ETL: Embedding Integration Services" from PDC05 mentioned this issue. SMO is needed.
I am still searching for the samples.
-ZZhang
Thursday, February 16, 2012
can I return output from stored procedure into an HTA to display in browser?
simple informtation about that tim a database was backed up. I owuld
like to create an HTA that operator types can look at to make sure
that the backups finished, can someone help me do this?
The stored procedure in called sp_lastback and the output looks like
this:
database days since backup timestamp of backup
dbase1 0 2004-10-14 00:41:21.000
dbase2 0 2004-10-14 00:08:36.000
dbase3 1 2004-10-13 22:46:57.000
Can this be done? If someone could help me with this simple problem, I
could probably reuse the same method a 100 useful ways.
Thanks in advance!"sumGirl" <emebohw@.netscape.net> wrote in message
news:a5e13cff.0410141529.23a19fd8@.posting.google.c om...
> Hi all. I have a stored procedure on my sql server that returns a
> simple informtation about that tim a database was backed up. I owuld
> like to create an HTA that operator types can look at to make sure
> that the backups finished, can someone help me do this?
> The stored procedure in called sp_lastback and the output looks like
> this:
> database days since backup timestamp of backup
> dbase1 0 2004-10-14 00:41:21.000
> dbase2 0 2004-10-14 00:08:36.000
> dbase3 1 2004-10-13 22:46:57.000
> Can this be done? If someone could help me with this simple problem, I
> could probably reuse the same method a 100 useful ways.
> Thanks in advance!
You'll probably get a better response in a group for HTA users. I guess you
could write a client script to execute the procedure with ADO, then loop
over the ResultSet and build the .hta file dynamically, but I have no idea
about any details.
Simon|||Here's a generic technique to render a resultset using dynamic html. There
may be better ways to accomplish the task, though.
<html>
<head>
<body>
<Script Language="VBScript"
Sub btnListBackups_OnClick()
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=SQLOLEDB" & _
";Data Source=" & "DBDELTA1" & _
";Integrated Security=SSPI"
Set recordSet = oConnection.Execute("EXEC tempdb..sp_lastback")
myResultTable = "<table border=""1"">"
myResultTable = myResultTable & "<tr>"
For i = 0 To recordSet.Fields.Count - 1
myResultTable = myResultTable & _
"<th>" & _
recordSet.Fields(i).Name & _
"</th>"
Next
myResultTable = myResultTable & "</tr>"
Do While Not recordSet.EOF
myResultTable = myResultTable & "<tr>"
For i = 0 To recordSet.Fields.Count - 1
myResultTable = myResultTable & _
"<td>" & _
recordSet.Fields(i).Value & _
"</td>"
Next
myResultTable = myResultTable & "</tr>"
recordSet.MoveNext
Loop
myResultTable = myResultTable & "</table>"
recordSet.Close
oConnection.Close
Results.innerHTML = myResultTable
End Sub
</script
<input type="button" id="btnListBackups" value="List Backups">
<hr>
<nobr Id=Results></nobr>
</body>
</html
--
Hope this helps.
Dan Guzman
SQL Server MVP
"sumGirl" <emebohw@.netscape.net> wrote in message
news:a5e13cff.0410141529.23a19fd8@.posting.google.c om...
> Hi all. I have a stored procedure on my sql server that returns a
> simple informtation about that tim a database was backed up. I owuld
> like to create an HTA that operator types can look at to make sure
> that the backups finished, can someone help me do this?
> The stored procedure in called sp_lastback and the output looks like
> this:
> database days since backup timestamp of backup
> dbase1 0 2004-10-14 00:41:21.000
> dbase2 0 2004-10-14 00:08:36.000
> dbase3 1 2004-10-13 22:46:57.000
> Can this be done? If someone could help me with this simple problem, I
> could probably reuse the same method a 100 useful ways.
> Thanks in advance!|||Thanks Dan! Thats exactly the kind of example I can run with!
Sunday, February 12, 2012
Can I output the result of sp_spaceused to a table ?
Field Data type
db_name char (80)
db_size char (20)
unallocated_space char (20)
reserved char (20)
data char (20)
index_size char (20)
unused char (20)
Then, I executed this command in SQL Analyzer :
INSERT INTO test01 EXEC sp_spaceused
But I only got this result :
Server: Msg 213, Level 16, State 7, Procedure sp_spaceused, Line 142
Insert Error: Column name or number of supplied values does not match table
definition
Can I output the result of : EXEC sp_spaceused to a table ?
Was my SQL statement correct or incorrect ?
sp_spaceused has two result sets, so no you can't do that directly...
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"cpchan" <cpchaney@.netvigator.com> wrote in message
news:c8t0tc$91f2@.imsp212.netvigator.com...
> Firstly, I created a table : test01 as follow :
> Field Data type
> db_name char (80)
> db_size char (20)
> unallocated_space char (20)
> reserved char (20)
> data char (20)
> index_size char (20)
> unused char (20)
> Then, I executed this command in SQL Analyzer :
> INSERT INTO test01 EXEC sp_spaceused
> But I only got this result :
> Server: Msg 213, Level 16, State 7, Procedure sp_spaceused, Line 142
> Insert Error: Column name or number of supplied values does not match
table
> definition
>
> Can I output the result of : EXEC sp_spaceused to a table ?
> Was my SQL statement correct or incorrect ?
>
>
|||Try looking at the code in master..sp_spaceused. You could probably pick
out the portions into separate procs. Would loose the features of new
sp_spaceused during a SQL Server version upgrade but if you are desperate
enough this is an option.
-Paritosh
"Aaron Bertrand - MVP" <aaron@.TRASHaspfaq.com> wrote in message
news:eoF5B4ZQEHA.3744@.TK2MSFTNGP10.phx.gbl...
> sp_spaceused has two result sets, so no you can't do that directly...
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.aspfaq.com/
>
>
> "cpchan" <cpchaney@.netvigator.com> wrote in message
> news:c8t0tc$91f2@.imsp212.netvigator.com...
> table
>
|||> Would loose the features of new
> sp_spaceused during a SQL Server version upgrade but if you are desperate
> enough this is an option.
Right, but to be honest, that is slightly safer than relying on the sp_ to
not change... since if you *could* do insert #table exec sp_spaceused and
the resultset changes, suddenly your code breaks. If your code is merely
*based on* the sp_ then it won't break when the sp_ changes.
Then again, your code would likely rely on calls to system tables such as
sysindexes etc. which are going to change and which will eventually
disappear, so neither method would be truly safe...
A
Can I output the result of sp_spaceused to a table ?
Field Data type
db_name char (80)
db_size char (20)
unallocated_space char (20)
reserved char (20)
data char (20)
index_size char (20)
unused char (20)
Then, I executed this command in SQL Analyzer :
INSERT INTO test01 EXEC sp_spaceused
But I only got this result :
Server: Msg 213, Level 16, State 7, Procedure sp_spaceused, Line 142
Insert Error: Column name or number of supplied values does not match table
definition
Can I output the result of : EXEC sp_spaceused to a table ?
Was my SQL statement correct or incorrect ?sp_spaceused has two result sets, so no you can't do that directly...
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"cpchan" <cpchaney@.netvigator.com> wrote in message
news:c8t0tc$91f2@.imsp212.netvigator.com...
> Firstly, I created a table : test01 as follow :
> Field Data type
> db_name char (80)
> db_size char (20)
> unallocated_space char (20)
> reserved char (20)
> data char (20)
> index_size char (20)
> unused char (20)
> Then, I executed this command in SQL Analyzer :
> INSERT INTO test01 EXEC sp_spaceused
> But I only got this result :
> Server: Msg 213, Level 16, State 7, Procedure sp_spaceused, Line 142
> Insert Error: Column name or number of supplied values does not match
table
> definition
>
> Can I output the result of : EXEC sp_spaceused to a table ?
> Was my SQL statement correct or incorrect ?
>
>|||Try looking at the code in master..sp_spaceused. You could probably pick
out the portions into separate procs. Would loose the features of new
sp_spaceused during a SQL Server version upgrade but if you are desperate
enough this is an option.
-Paritosh
"Aaron Bertrand - MVP" <aaron@.TRASHaspfaq.com> wrote in message
news:eoF5B4ZQEHA.3744@.TK2MSFTNGP10.phx.gbl...
> sp_spaceused has two result sets, so no you can't do that directly...
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.aspfaq.com/
>
>
> "cpchan" <cpchaney@.netvigator.com> wrote in message
> news:c8t0tc$91f2@.imsp212.netvigator.com...
> table
>|||> Would loose the features of new
> sp_spaceused during a SQL Server version upgrade but if you are desperate
> enough this is an option.
Right, but to be honest, that is slightly safer than relying on the sp_ to
not change... since if you *could* do insert #table exec sp_spaceused and
the resultset changes, suddenly your code breaks. If your code is merely
*based on* the sp_ then it won't break when the sp_ changes.
Then again, your code would likely rely on calls to system tables such as
sysindexes etc. which are going to change and which will eventually
disappear, so neither method would be truly safe...
A
Can I output the result of sp_spaceused to a table ?
Field Data type
db_name char (80)
db_size char (20)
unallocated_space char (20)
reserved char (20)
data char (20)
index_size char (20)
unused char (20)
Then, I executed this command in SQL Analyzer :
INSERT INTO test01 EXEC sp_spaceused
But I only got this result :
Server: Msg 213, Level 16, State 7, Procedure sp_spaceused, Line 142
Insert Error: Column name or number of supplied values does not match table
definition
Can I output the result of : EXEC sp_spaceused to a table ?
Was my SQL statement correct or incorrect ?sp_spaceused has two result sets, so no you can't do that directly...
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"cpchan" <cpchaney@.netvigator.com> wrote in message
news:c8t0tc$91f2@.imsp212.netvigator.com...
> Firstly, I created a table : test01 as follow :
> Field Data type
> db_name char (80)
> db_size char (20)
> unallocated_space char (20)
> reserved char (20)
> data char (20)
> index_size char (20)
> unused char (20)
> Then, I executed this command in SQL Analyzer :
> INSERT INTO test01 EXEC sp_spaceused
> But I only got this result :
> Server: Msg 213, Level 16, State 7, Procedure sp_spaceused, Line 142
> Insert Error: Column name or number of supplied values does not match
table
> definition
>
> Can I output the result of : EXEC sp_spaceused to a table ?
> Was my SQL statement correct or incorrect ?
>
>|||You can do that at a table level:
Example for Northwind Employees table.
Create Table #Temp1
(Tablename CHAR(80),
rows int,
un_space VARCHAR(50),
reserved VARCHAR(50),
data VARCHAR(50),
index_size VARCHAR(50))
GO
Insert into #Temp1
Exec sp_spaceused 'Employees'
GO
Select * from #Temp1
GO
Drop table #Temp1
GO
>--Original Message--
>Firstly, I created a table : test01 as follow :
>Field Data type
>db_name char (80)
>db_size char (20)
>unallocated_space char (20)
>reserved char (20)
>data char (20)
>index_size char (20)
>unused char (20)
>Then, I executed this command in SQL Analyzer :
>INSERT INTO test01 EXEC sp_spaceused
>But I only got this result :
>Server: Msg 213, Level 16, State 7, Procedure
sp_spaceused, Line 142
>Insert Error: Column name or number of supplied values
does not match table
>definition
>
>Can I output the result of : EXEC sp_spaceused to a
table ?
>Was my SQL statement correct or incorrect ?
>
>.
>|||Try looking at the code in master..sp_spaceused. You could probably pick
out the portions into separate procs. Would loose the features of new
sp_spaceused during a SQL Server version upgrade but if you are desperate
enough this is an option.
-Paritosh
"Aaron Bertrand - MVP" <aaron@.TRASHaspfaq.com> wrote in message
news:eoF5B4ZQEHA.3744@.TK2MSFTNGP10.phx.gbl...
> sp_spaceused has two result sets, so no you can't do that directly...
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.aspfaq.com/
>
>
> "cpchan" <cpchaney@.netvigator.com> wrote in message
> news:c8t0tc$91f2@.imsp212.netvigator.com...
> > Firstly, I created a table : test01 as follow :
> >
> > Field Data type
> > db_name char (80)
> > db_size char (20)
> > unallocated_space char (20)
> > reserved char (20)
> > data char (20)
> > index_size char (20)
> > unused char (20)
> >
> > Then, I executed this command in SQL Analyzer :
> >
> > INSERT INTO test01 EXEC sp_spaceused
> >
> > But I only got this result :
> >
> > Server: Msg 213, Level 16, State 7, Procedure sp_spaceused, Line 142
> > Insert Error: Column name or number of supplied values does not match
> table
> > definition
> >
> >
> > Can I output the result of : EXEC sp_spaceused to a table ?
> > Was my SQL statement correct or incorrect ?
> >
> >
> >
>|||> Would loose the features of new
> sp_spaceused during a SQL Server version upgrade but if you are desperate
> enough this is an option.
Right, but to be honest, that is slightly safer than relying on the sp_ to
not change... since if you *could* do insert #table exec sp_spaceused and
the resultset changes, suddenly your code breaks. If your code is merely
*based on* the sp_ then it won't break when the sp_ changes.
Then again, your code would likely rely on calls to system tables such as
sysindexes etc. which are going to change and which will eventually
disappear, so neither method would be truly safe...
A|||Thanks to everybodies.
"Tom" <anonymous@.discussions.microsoft.com> wrote in message
news:115ac01c441a1$917301b0$a001280a@.phx.gbl...
> You can do that at a table level:
> Example for Northwind Employees table.
>
> Create Table #Temp1
> (Tablename CHAR(80),
> rows int,
> un_space VARCHAR(50),
> reserved VARCHAR(50),
> data VARCHAR(50),
> index_size VARCHAR(50))
> GO
> Insert into #Temp1
> Exec sp_spaceused 'Employees'
> GO
> Select * from #Temp1
> GO
> Drop table #Temp1
> GO
>
> >--Original Message--
> >Firstly, I created a table : test01 as follow :
> >
> >Field Data type
> >db_name char (80)
> >db_size char (20)
> >unallocated_space char (20)
> >reserved char (20)
> >data char (20)
> >index_size char (20)
> >unused char (20)
> >
> >Then, I executed this command in SQL Analyzer :
> >
> >INSERT INTO test01 EXEC sp_spaceused
> >
> >But I only got this result :
> >
> >Server: Msg 213, Level 16, State 7, Procedure
> sp_spaceused, Line 142
> >Insert Error: Column name or number of supplied values
> does not match table
> >definition
> >
> >
> >Can I output the result of : EXEC sp_spaceused to a
> table ?
> >Was my SQL statement correct or incorrect ?
> >
> >
> >
> >.
> >
can i make optional OUTPUT paramater?
can i make one of the output parameter be optional?
not sent the parater to the procedure
Tnx in advanceJust give it a default value of NULL
procname
(
@.p1 INT = NULL OUTPUT
) AS
BEGIN
...
END|||> when i calling stored procedure
> can i make one of the output parameter be optional?
>
sure. just give the parameter a default value e.g.
create procedure dbo.proc
(
@.value varchar(10)=null output
)
as
...
James