首页 \ 问答 \ 在SQL Server 2008中的存储过程中导出为CSV(Export to CSV in stored procedure in SQL Server 2008)

在SQL Server 2008中的存储过程中导出为CSV(Export to CSV in stored procedure in SQL Server 2008)

我有一个存储过程,创建一个临时表,并有大量的数据。 我尝试了以下两种方法。 我可以使用导出实用程序手动执行此操作或将结果导入文件设置,但我想将代码嵌入到我的存储过程中,以便我可以安排批处理作业并忘记它。 我也不希望我们SSIS有很多原因。

我发现的热门解决方案是:

bcp "select * from WHSE.Customer" queryout ExcelTest.csv -t, -c -S . -d Server1 -T

SQLCMD -S . -d Server1 -Q “"select * from WHSE.Customer sp” -s “,” -o “d:\result.csv

在BCP中,它在BCP上出错,如果我在前面添加了EXECUTE ,我会收到错误:

'queryout'附近的语法不正确。

除了SQLCMD-S上的错误之外, SQLCMD也是如此,这取决于我是否使用Execute命令。

这似乎应该很简单,我已经找到了很多答案,但没有一个真正起作用。 它似乎应该是世界上最基本的东西, SELECT * INTO MYFILE.CSV FROM MYTABLE


I have a stored procedure that creates a temp table and has tons of data. I have tried both of the following. I can do it manually with the export utility or results to file settings, but I would like to embed the code in my stored procedure so I can schedule the batch job and forget it. Also I do not want to us SSIS for many reasons.

Popular solution I have found are :

bcp "select * from WHSE.Customer" queryout ExcelTest.csv -t, -c -S . -d Server1 -T

SQLCMD -S . -d Server1 -Q “"select * from WHSE.Customer sp” -s “,” -o “d:\result.csv

In the BCP it get an error on BCP, if I added an EXECUTE in front I get an error:

Incorrect syntax near 'queryout'.

The same goes with the SQLCMD except error on SQLCMD or -S depending on if I use the Execute command.

This seems like it should be simple and I have found TONS of answers, but none actually work. It seems like it should be the most basic thing in the world, SELECT * INTO MYFILE.CSV FROM MYTABLE essentially.


原文:https://stackoverflow.com/questions/34346000
更新时间:2022-10-25 06:10

最满意答案

注意,API抱怨请求 ,而不是后续。 您可能关注了50个用户,但您已经发出超过5000的API请求。使用您当前的代码,只需要100页的刷新就可以达到该限制。 可能听起来像很多刷新,但如果你正在调试/开发代码,那么假设你可以相对容易地超过100刷新阈值是合理的。

要缓解此问题,如果您仍在使用/调试此代码,请将后续数量从50减少到1或2.一旦您的代码正常工作,然后恢复以前的数量。 我建议你也可以缓存返回对象,持续5或10分钟。 这样您就不必担心超出API限制。


Note, the API is complaining about requests, not follows. You may be following 50 users but you have made API requests that exceed 5000. With your current code, it will only take 100 page refreshes for you to reach that limit. Might sound like a lot of refreshes but if you are debugging/developing code then it is plausible to assume that you could exceed the 100 refresh threshold with relative ease.

To mitigate this problem, if you are still working/debugging this code then reduce the number of follows from 50 to 1 or 2. Once your code is working then reinstate the previous number of follows. I would recommend you cache the return objects too, for 5 or 10 minutes. That way you won't need to worry about exceeding the API limits.

相关问答

更多
  • Instagram限制了各种终端在其API中返回的结果数量,并且他们随意更改这些限制,没有任何警告,可能是为了处理服务器负载。 存在几个类似的线程: Instagram API不会执行计数参数 在Instagram API中显示超过20张照片 Instagram API:如何获取所有用户媒体? (请参阅回答评论, -1返回1的结果)。 350 API请求限制 Instagram API:如何获取所有用户媒体? 简而言之,您将无法增加返回的最大行数,并且您将陷入分页。 Instagram limits the ...
  • 首先:您可以将媒体限制增加到最多33张照片。 您应该在查询字符串上使用count参数: https://api.instagram.com/v1/tags/nofilter/media/recent?count=33&access_token=YOUR_ACCESS_TOKEN 即将导航到上一页,在我看来Instagram的响应将始终与最新发布的照片。 来自Instagram API: MIN_TAG_ID Return media before this min_tag_id. MAX_TAG_ID ...
  • 你说得对,Instagram API每次呼叫只能返回20张图像。 所以你必须使用分页功能。 如果您正在尝试使用API控制台。 您将首先允许API控制台通过您的Instagram登录进行身份验证。 为此,您需要在“身份验证”下拉列表中选择OAUTH2。 一旦验证,使用左侧菜单选择用户/ {user-id} / media / recent endpoint。 所以为了{user-id}的这个帖子,你可以用self替换它。 然后,您将使用您的帐户来检索信息。 最低限度是为此端点执行GET所需要的。 一旦你发送, ...
  • 官方文档没有说明访问令牌的任何限制。 但是他们每小时有限制。 应用全局速率限制,包括应用程序在1小时滑动窗口中进行的所有API调用,无论特定端点如何。 限制彼此独立地应用; 经过身份验证的呼叫不会计入未经身份验证的呼叫的速率限制,反之亦然。 所以答案是否定的,截至目前。 The official documentation does not say about any limits about access tokens. However they have limits per hour. Global ...
  • 使用此API: https://api.instagram.com/v1/users/self/media/recent?access_token={access-token} 这将获得你的照片,(但它看起来像你发布的access_token ,该用户没有张贴任何照片,所以它将返回空数组) 用它来获取其他用户的照片: https://api.instagram.com/v1/users/{user-id}/media/recent?access_token={access-token} 您应该使用pub ...
  • 你看过Instagram API Docs了吗? 这看起来像你在寻找: https://api.instagram.com/v1/users/[user-id]/relationship?access_token=[ACCESS-TOKEN] 修改当前用户与目标用户之间的关系。 PARAMETERS: ACCESS_TOKEN A valid access token. ACTION One of: follow/unfollow/block/unblock/approve/deny. 因此,如 ...
  • 您可以使用COUNT参数指定要返回的图像数量。 尝试这个: $result = fetchData("https://api.instagram.com/v1/users/ID-GOES-HERE/media/recent/?access_token=TOKEN-GOES-HERE&count=6"); 如果你想在你身边检索更多的记录和页面,请查看min_id和max_id进行分页。 You can specify the number of images to return using the COUN ...
  • 由于第一个问题,我认为Instagram API开发人员假设您将正确处理429错误代码(当您超过小时限制时它将被返回)并且您不会垃圾邮件他们的API。 此外,在Instagram文档中,您可以找到以下声明: 如果我们使用您的应用检测到某人的垃圾行为,您也可能会收到HTTP响应代码为400(错误请求)的回复。 这些错误与速率限制无关。 所以我认为,如果从Instagram的角度来看,你收到很多400回复,这是你的应用程序的用户错误。 关于未记录端点的速率限制,您应该直接联系Instagram支持 Due to ...
  • 注意,API抱怨请求 ,而不是后续。 您可能关注了50个用户,但您已经发出超过5000的API请求。使用您当前的代码,只需要100页的刷新就可以达到该限制。 可能听起来像很多刷新,但如果你正在调试/开发代码,那么假设你可以相对容易地超过100刷新阈值是合理的。 要缓解此问题,如果您仍在使用/调试此代码,请将后续数量从50减少到1或2.一旦您的代码正常工作,然后恢复以前的数量。 我建议你也可以缓存返回对象,持续5或10分钟。 这样您就不必担心超出API限制。 Note, the API is complain ...
  • 要注销用户,您应该只删除令牌。 如果用户不希望您的应用访问其数据,则会取消您的应用访问权限。 如果您想为用户提供从应用程序注销的方法,您可以在登录实现上执行此操作(当然,如果您有后端),否则只需将用户发送回登录屏幕并删除令牌即可。 To logout the user you should only delete the token. If the user doesn't want your app to access their data they will cancel your app access ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。