常用sql 语句.

查询是否有小写字母 

Select * FROM         ICILOC   WHERE     (ITEMNO LIKE '%[a-z]%' COLLATE chinese_prc_bin)

查询某段时间,是否有空房。

select *,
, (gs_stock-isnull(aac.maxqty,0)) as gs_stock from VGoods_FatherCategory_House_Extend left join (select houseorder_gsid,max(houseorder_qty)as maxqty from houseorderdetail where houseorder_date >=@indate and houseorder_date <=@outdate group by houseorder_gsid) AS aac on aac.houseorder_gsid=VGoods_FatherCategory_House_Extend.gs_id

×当as 子表失败,注意是否每个字段都有名字或别名。

如何表示单引号。2个单引号来表示。

查询某段时间,是否有空房。存储过程。

ALTER PROCEDURE [dbo].[spGoodsHouseExtend](@indate nvarchar(50),@outdate nvarchar(50),@where nvarchar(50))
AS
BEGIN
SET NOCOUNT ON;
declare @strsql as nvarchar(2500)
set @strsql='select * from (
select house_id, house_gsid, house_area, house_wifi, house_tel, house_type, house_breakfast, house_maxpeoplecount, house_extend, house_window, house_show, gs_id, gs_name, gs_type, gs_spid, gs_price,
gs_desc, gs_level, gs_smpledesc, gs_smallpic, gs_bigpic, gs_pics, gs_score, gs_extend, gs_keeps, gs_orderrange, sp_id, sp_cgid, sp_display, sp_name, sp_city, sp_address, sp_flag, sp_smallpic,
sp_bigpic, sp_score, sp_extend, sp_level, sp_status, sp_tels, sp_tel, sp_stare, sp_action, sp_online, sp_goodsWeakOpen, sp_starttime, cg_fatherid, cg_name, cg_pic, cg_extend, sp_validdays,
sp_goodsRule
, (gs_stock-isnull(aac.maxqty,0)) as gs_stock ,isnull(aac.maxqty,0) as bb from VGoods_FatherCategory_House_Extend left join (select houseorder_gsid,max(houseorder_qty)as maxqty from houseorderdetail where houseorder_date >='''+@indate+''' and houseorder_date <='''+@outdate+''' group by houseorder_gsid) AS aac on aac.houseorder_gsid=VGoods_FatherCategory_House_Extend.gs_id
) as abc '+@where

execute(@strsql);
END

原文地址:https://www.cnblogs.com/lsfv/p/3224527.html