| Author |
Topic |
|
ra_pa_ta
Starting Member
13 Posts |
Posted - 2011-08-30 : 14:36:33
|
| How do I count the records returned by the BCP command and store it in a table? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ra_pa_ta
Starting Member
13 Posts |
Posted - 2011-08-30 : 15:24:35
|
| Can you please explain to me in more detail ?Here is my code :Set @strSQL = 'bcp ' + @strDatabaseName + '.dbo.' + @strTableName + ' ' + @strINorOUT + ' ' + @strLocalPath + 'HSO_'+@strTextFile + @strFieldInfo + @strRowTerm + @strErrorFile + ' -S ' + @@servername + ' -T -c ' + @strFirstRow + @strLastRowExec @intError = master.dbo.xp_cmdshell @strSQL |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ra_pa_ta
Starting Member
13 Posts |
Posted - 2011-08-30 : 22:09:18
|
| How do i collect the row count and store it in a table ?Please correct my syntax belowdeclare @sql nvarchar(500)declare @rowcount intset @sql = 'select count(*) from ' + @strTableNameUpdate dbo.tbltest t set intRowCount = exec (@sql)where @strTableName = t.strTableName |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ra_pa_ta
Starting Member
13 Posts |
Posted - 2011-08-30 : 23:31:30
|
| No it does not have to be .I have views when queried everyday would return a different row count which will be bcp to generate flat files. So to begin with I was trying to generate the row count of the flat files . If that is not possible then I can still try to count the rows of the result of these views and update the log table which stores one record for each file extracted everyday .Do I need to write a cursor to loop through all the views and select the rowcount ? |
 |
|
|
ra_pa_ta
Starting Member
13 Posts |
Posted - 2011-09-01 : 12:17:16
|
| Thanks for your help . Today I resovlved my issue with a work around . I built a view that would select the counts of records from each view that I am bcp from like this :create view [dbo].[uvwFixMan](DataFileName, DataSourceName, RunDate, RecordCount,[Version],Comments)as /* Creates count of records for extract . */select 'Table_'+ CONVERT(varchar,getdate(),112) + '.dat' as DataFileName,'uvwChannel' as DataSourceName,CONVERT(varchar,getdate(),101)as RunDate,Cast(COUNT(*) as varchar) as RecordCount,'01' as Version,'NoComments' as Commentsfrom dbo.uvwChannelUNIONselect 'Table'+ CONVERT(varchar,getdate(),112) + '.dat' as DataFileName,'uvwCustomerPriceChoice' as DataSourceName,CONVERT(varchar,getdate(),101)as RunDate,Cast(COUNT(*) as varchar) as RecordCount,'01' as Version,'NoComments' as Commentsfrom dbo.uvwCustomerPriceChoiceUNIONetc |
 |
|
|
|