首页 \ 问答 \ tSQL CASE来控制执行(tSQL CASE to control execution)

tSQL CASE来控制执行(tSQL CASE to control execution)

我理解如何使用case语句返回不同的值:

SELECT CASE Color
         WHEN 'Blue' THEN 'Water'
         WHEN 'Black' THEN 'Oil'
         WHEN 'Red' THEN 'Blood'
       END
  FROM dbo.Liquid

有没有办法用它来控制流量而不是IF-ELSE,即

DECLARE @Color varchar()
SELECT @Color = Color FROM dbo.Liquid WHERE ID = @MyID

CASE (@Color)
  WHEN 'Blue' THEN SELECT 'Water'
  WHEN 'Black' THEN SELECT 'Oil'
  WHEN 'Red' THEN PRINT 'HELP! I''m bleeding!'
END

I understand how to use a case statement to return different values:

SELECT CASE Color
         WHEN 'Blue' THEN 'Water'
         WHEN 'Black' THEN 'Oil'
         WHEN 'Red' THEN 'Blood'
       END
  FROM dbo.Liquid

Is there a way to use it to control flow instead of IF-ELSE, i.e.

DECLARE @Color varchar()
SELECT @Color = Color FROM dbo.Liquid WHERE ID = @MyID

CASE (@Color)
  WHEN 'Blue' THEN SELECT 'Water'
  WHEN 'Black' THEN SELECT 'Oil'
  WHEN 'Red' THEN PRINT 'HELP! I''m bleeding!'
END

原文:https://stackoverflow.com/questions/1959126
更新时间:2022-01-13 12:01

最满意答案

好的,我在这里做的第一件事就是删除var bmp:Bitmap = new Bitmap 。 你正在创建一个你并不真正需要的引用,所以让我们完全摆脱它。

现在,在on_img_loaded方法中,您将要为每个加载的图像创建一个新的Bitmap

var bmp:Bitmap = e.currentTarget.content;

然后,您需要将事件侦听器直接添加到InteractiveObject而不是舞台。 位图不是InteractiveObjects ,因此我们需要在添加侦听器之前将其包装在其他内容中。

var sprite: Sprite = new Sprite();
sprite.addChild(bmp);
addChild(sprite);
sprite.addEventListener(MouseEvent.CLICK, onClick);

最后,创建一个从images_container删除单击的Bitmap的方法(注意这里我删除了嵌套函数 - 这可以防止参数模糊,通常是很好的做法)。

function onClick(e:MouseEvent):void
{
    images_container.removeChild(e.currentTarget);
}

这是完整的相关代码(未经测试)。

//remove var bmp:Bitmap = new Bitmap from the beginning of the code
function on_img_loaded(e:Event):void {
    e.currentTarget.removeEventListener(Event.COMPLETE, on_img_loaded);
    var bmp:Bitmap = e.currentTarget.content;
    bmp.x = 600, bmp.width = bmp.height = 80;
    bmp.y = images_container.numChildren * (bmp.height + img_margin);
    var sprite: Sprite = new Sprite();
    sprite.addChild(bmp);
    addChild(sprite);
    images_container.addChild(sprite);
    sprite.addEventListener(MouseEvent.CLICK, onClick);
}

function onClick(e:MouseEvent):void
{
    e.currentTarget.removeEventListener(MouseEvent.CLICK, onClick)
    images_container.removeChild(e.currentTarget as DisplayObject);
}

希望这可以帮助!


Okay, first thing I did here was remove var bmp:Bitmap = new Bitmap. You're creating a reference you don't really need, so let's get rid of that altogether.

Now, in your on_img_loaded method, you're going to want to create a new Bitmap for each loaded image.

var bmp:Bitmap = e.currentTarget.content;

Then, you'll need to add the event listener directly to an InteractiveObject rather than the stage. Bitmaps are not InteractiveObjects, so we'll need to wrap it in something else before adding the listener.

var sprite: Sprite = new Sprite();
sprite.addChild(bmp);
addChild(sprite);
sprite.addEventListener(MouseEvent.CLICK, onClick);

Finally, create a method to remove the clicked Bitmap from images_container (note here I removed the nested function - this prevents argument ambiguity and is generally good practice).

function onClick(e:MouseEvent):void
{
    images_container.removeChild(e.currentTarget);
}

This is the relevant code in its entirety (untested).

//remove var bmp:Bitmap = new Bitmap from the beginning of the code
function on_img_loaded(e:Event):void {
    e.currentTarget.removeEventListener(Event.COMPLETE, on_img_loaded);
    var bmp:Bitmap = e.currentTarget.content;
    bmp.x = 600, bmp.width = bmp.height = 80;
    bmp.y = images_container.numChildren * (bmp.height + img_margin);
    var sprite: Sprite = new Sprite();
    sprite.addChild(bmp);
    addChild(sprite);
    images_container.addChild(sprite);
    sprite.addEventListener(MouseEvent.CLICK, onClick);
}

function onClick(e:MouseEvent):void
{
    e.currentTarget.removeEventListener(MouseEvent.CLICK, onClick)
    images_container.removeChild(e.currentTarget as DisplayObject);
}

Hope this helps!

相关问答

更多
  • 例如,查看这个问题: 装载机锁定错误 加载程序锁定的一般想法:系统在锁内的DllMain运行代码(作为同步锁)。 因此,在DllMain运行不重要的代码是“要求死锁” 我刚才提到的答案是基于这篇文章: 在你的DllMain不要做任何可怕的事情的另一个原因:无意的死锁 您的DllMain函数在加载程序锁中运行,这是操作系统允许您在其中一个内部锁被锁定时运行代码的几次之一。 这意味着您必须格外小心,不要违反DllMain的锁定层级; 否则,你正在寻求僵局。 加载程序锁定由需要访问加载到进程中的DLL列表的任何函 ...
  • 好的,我在这里做的第一件事就是删除var bmp:Bitmap = new Bitmap 。 你正在创建一个你并不真正需要的引用,所以让我们完全摆脱它。 现在,在on_img_loaded方法中,您将要为每个加载的图像创建一个新的Bitmap 。 var bmp:Bitmap = e.currentTarget.content; 然后,您需要将事件侦听器直接添加到InteractiveObject而不是舞台。 位图不是InteractiveObjects ,因此我们需要在添加侦听器之前将其包装在其他内容中 ...
  • 用这个: @Override public void onLoadFinished(Loader loader, Data data) { makeWorkWithData(); stopLoader(id); } void stopLoader(int id) { getLoaderManager().destroyLoader(id); } 当需要再次请求时调用getLoaderManager().restartLoader()... Use this ...
  • 你不能用css-loader和style-loader来做到这一点,但你可以使用react-css-modules将特定的类导入到你的反应文件中。 它只将必要的css加载到文档中,并且还会在加载时为您的class创建一个唯一的名称。 通过这个,你可以在不同的组件中使用相同的类名和不同的样式! You cannot do this with css-loader and style-loader but you can use react-css-modules to import a specific cl ...
  • 使用承诺将解决您的问题。 更新的小提琴也https://jsfiddle.net/3espztjw/5/ $("#startProcess").click(function(){ $("#loaderImg").show(); $.when(showSomeProcess()).then(function(){ $("#loaderImg").hide(); }) }); var showSomeProcess=function(){ var deferr ...
  • 您需要分发存档。 以下是类似的问题: Application Loader中的托管内容包是什么? You need to distribute the the archive. Here's a similar questions: What is Hosted Content Package in the Application Loader?
  • 我已经实现了, 1)创建自定义字段并绘制一个默认图像。 2)向对象添加了像url,size等图像属性。 3)将该Object添加到该Cookie 4)将字段添加到管理器后,启动一个新线程。 5)在该线程中获取cookie属性并下载每个图像。 上面的过程不会阻止您停止下载,直到屏幕被破坏并将下载所有图像。 稍后您可以添加您的要求。 I Have implemented like, 1) created custom field and painted one default image. 2) added i ...
  • 这与ImageLoader没有问题。它与您的服务器端有问题。 有服务器关闭或主机名可能是错误的或您无法授予Internet访问权限.. 因此,请尝试向清单文件添加权限:
    您需要一个单独的生产配置,该配置不包括条目中的开发服务器或热加载器。 请参阅下面的我的webpack配置的简化版本。 如果应用程序运行的是类似于webpack -p东西,那么LAUNCH_COMMAND就是production并使用productionConfig 。 但这只是一种方法。 您也可以有一个单独的配置文件用于生产。 像webpack.prod.config.js类的webpack.prod.config.js 。 然后,您可以使用webpack -p --config webpack.prod. ...
  • 您可以使用css使用scale属性 .loading-directive .loader { position: relative; margin: 0 auto; width: 65px; height: 64px; zoom: 1; transform: scale(1.5, 1.5); -webkit-transform: scale(1.5, 1.5); -moz-transform: scale(1.5, 1.5); -ms-transform: scale(1 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)