Sql Server 2012中的查询需要帮助 [英] Help needed in queries in Ms Sql Server 2012

查看:84
本文介绍了Sql Server 2012中的查询需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql中有以下表格

(Subid,UserID,PackageID,Startdate,EndDate,Maxnoffication,maxarticles,ispaid,isactive)

values(13,3, 2,8-5-2014,8-6-2014,150,150,true,true);



i必须应用以下查询进行身份验证,当用户登录时



1 - 检查用户的帐户中是否有任何活动包,如果没有,则返回false,

else

如果有包然后首先检查是今天是包的结束日期或如果余额意味着最大通知或文章是0 ..在两种情况下设置是活动的==假。

如果他有一些剩下的天数和剩余余额,然后返还余额。



另一种情况是,如果通知== 0和文章== n,有些日子还剩下到结束日期th package,然后用户可以购买一个新包,然后将以前的包余额添加到新包中,前一个设置为Isactive == false。



想要获得像这样的商店程序下面的逻辑...



I have following table in sql
(Subid, UserID, PackageID,Startdate,EndDate,Maxnoffication,maxarticles,ispaid,isactive)
values(13,3,2,8-5-2014,8-6-2014,150,150,true,true);

i have to apply following queries for authentication, when user login

1 - Check if user has any packages in his account active, if not then return false,
else
if has packages then first check is has today is the end date of package or if balance mean that max notification or articles is 0.. in both case set is active == false.
if he has some days left and balance left, then return the balance.

another case is that if notification == 0 and articles == n and some days left to end-date of th package, then user can purchase a new package, then previous balance of package is added to new one, and previous one is set Isactive == false.

Want to Get a store procedure like the logic below...

IF EXISTS (Select SubscriptionId from TblSubscription where UserId = 3 and IsActive = 1)
{
return @haspackage = 1
Set @Subid = (Select SubscriptionId from TblSubscription where UserId = 3 and IsActive = 1)
If ( StartDate <= GETDATE() <= FinishDate )
{
set @maxnotificion = (SELECT Maxnoffication FROM TleSubscription  Where Subid = @Subid)
set @maxarticles = (SELECT maxarticles FROM TleSubscription  Where Subid = @Subid)
}
}
else
{
return @haspackage = 0}

推荐答案

我建​​议从这里开始:演练:显示使用GridView Web服务器控件中的存储过程的数据 [ ^ ]

如何:创建并执行返回行的SQL语句 [ ^ ]
I'd suggest to start here: Walkthrough: Displaying Data Using a Stored Procedure in the GridView Web Server Control[^]
How to: Create and Execute an SQL Statement that Returns Rows[^]


这篇关于Sql Server 2012中的查询需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆