需要有关 SQL 2000 存储过程的帮助

发布于 2024-09-10 16:38:44 字数 223 浏览 4 评论 0原文

这是我的逻辑。

我有一个文章表和一个匹配的图像表。图像以二进制格式存储。每个图像表都有每个图像的 2 个实例,这是因为我有 2 个尺寸。 300 x 200 和 500 x 400,其行由 ImageSize 分隔

我想编写一个存储过程来检查 ImageSize=3 是否可用,如果不可用,则从 ImageSize=2 检索。

如何设置我的存储过程来执行此操作?

谢谢

This is my logic.

I have an articles table and a matching images tables. The images are stored in binary format. Each image table has 2 instances of each image, this is because I have 2 sizes. 300 x 200 and 500 x 400 with their rows separated by ImageSize

I want to write a stored procedure that checks if ImageSize=3 is available and if not, then retrieve from ImageSize=2.

How can I set up my stored procedure to do this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦巷 2024-09-17 16:38:44

您可以使用简单的 top 1 找到最大尺寸的图像:

create procedure dbo.GetImage(
    @ImageName varchar(50))
as
select  top 1 image
from    ImageTable
where   ImageName = @ImageName
order by
        ImageSize desc

You can find the highest size image with a simple top 1:

create procedure dbo.GetImage(
    @ImageName varchar(50))
as
select  top 1 image
from    ImageTable
where   ImageName = @ImageName
order by
        ImageSize desc
贵在坚持 2024-09-17 16:38:44

安多马尔的回应是完全有效且非常优雅的 - 如果你想要一些更“脚踏实地”的东西,考虑到未来可能涉及其他数值,请尝试这个:

CREATE PROCEDURE dbo.FetchImage(@ImageName VARCHAR(255))
AS
   IF EXISTS(SELECT * FROM dbo.ImageTable
             WHERE ImageName = @ImageName AND ImageSize = 3)
      SELECT
          Image
      FROM
          dbo.ImageTable
      WHERE
          ImageName = @ImageName AND ImageSize = 3
   ELSE
      SELECT
          Image
      FROM
          dbo.ImageTable
      WHERE
          ImageName = @ImageName AND ImageSize = 2

这基本上做了同样的事情 - 但它会继续返回 ImageSize = 3Image,即使您突然也有 4、5 等图像大小代码。

Andomar's response is completely valid and very elegant - if you want something more "down to earth", that takes into account there might be other number values involved in the future, try this:

CREATE PROCEDURE dbo.FetchImage(@ImageName VARCHAR(255))
AS
   IF EXISTS(SELECT * FROM dbo.ImageTable
             WHERE ImageName = @ImageName AND ImageSize = 3)
      SELECT
          Image
      FROM
          dbo.ImageTable
      WHERE
          ImageName = @ImageName AND ImageSize = 3
   ELSE
      SELECT
          Image
      FROM
          dbo.ImageTable
      WHERE
          ImageName = @ImageName AND ImageSize = 2

That basically does the same thing - but it'll continue to return the Image for ImageSize = 3 even if you suddenly also have image sizes codes of 4, 5, and so forth.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文