从另一个SQL表中选择数据以添加到字符串文本

时间:2016-09-13 23:23:46

标签: sql asp.net vb.net

以下代码选择价格为3的随机项目(照片)并将其作为字符串传递给我的网站..

  SELECT count(distinct Client.id)
  FROM Client
  INNER JOIN Order ON Order.id = Client.id
                  AND Order.storeId = Client.storeId
  WHERE Order.date BETWEEN '12-09-2016 16:00:00' AND '13-09-2016 16:00:00'

以上工作完美,但我还不知道SQL还没有完成以下工作..

我还需要选择

    SELECT TOP 3 
    thisweeksDate
    ,'<br/><a href="catalog/images/' 
                 + [filename] + 
                 '"    class="nyroModal" rel="gal" title="' 
                 + [price] + 
                 '" ><img   src="catalog/images/thumbnails/' 
                  + [filename] + 
                  + '" /></a>' 
                  + [price] 
     as strText
    ,fileID
    FROM [OCBUser].[tblItems]
    WHERE thisweeksDate = @thisweeksDate and price <> ''
    ORDER BY NEWID()

并将其添加到带有超链接前缀的strText中,以便可以单击它。所以它需要像......那样的东西。

friendlyOrderID from [OCBUser].[tblOrders] where [OCBUser].[tblItems].accountID = [OCBUser].[tblOrders].accountID

有什么想法吗?

非常感谢。

1 个答案:

答案 0 :(得分:1)

使用联接

  SELECT TOP 3 thisweeksDate, '<br/><a href="catalog/images/' + [filename] + '"    class="nyroModal" rel="gal" title="' + [price] + '" ><img   src="catalog/images/thumbnails/' + [filename] + '" /></a>' + [price] as strText, fileID
  ,'<a href="www.mysite.com/' + [friendlyorderID] + '">link</a>'

  FROM [OCBUser].[tblItems]
  JOIN [OCBUser].[tblOrders] on [OCBUser].[tblItems].accountID = [OCBUser].[tblOrders].accountID 
  WHERE thisweeksDate = @thisweeksDate and price <> ''
  ORDER BY NEWID()