vcujackson
Technical User
I have the following code to be used in a stored procedure to ask for a datetime @Giftdate (ie 2009-06-07 00:00:00).
I am doing a union on the same table (gifttable) I am using an alias as you can see here. My question is
1. Can I declare the two @Giftdates as I have done here to tell them apart
2. Based on the alias set up, should I be able to save this as a stored procedure and run this.
3. Have I formatted the datetime correctly
Create Proceedure NGP_Balance_Parameter
@Giftdateg --gift
@Giftdatep --pledge
SELECT g.giftid,g.giftdate
from
gifttable g
where g.giftdate >=@Giftdateg and
g.giftdate<=@Giftdateg
and g.gifttype = ('g')
union
SELECT p.giftid,p.giftdate
from
gifttable p
where p.giftdate >=@Giftdatep
and p.giftdate <=@Giftdatep
and p.gifttype = ('p')
I am doing a union on the same table (gifttable) I am using an alias as you can see here. My question is
1. Can I declare the two @Giftdates as I have done here to tell them apart
2. Based on the alias set up, should I be able to save this as a stored procedure and run this.
3. Have I formatted the datetime correctly
Create Proceedure NGP_Balance_Parameter
@Giftdateg --gift
@Giftdatep --pledge
SELECT g.giftid,g.giftdate
from
gifttable g
where g.giftdate >=@Giftdateg and
g.giftdate<=@Giftdateg
and g.gifttype = ('g')
union
SELECT p.giftid,p.giftdate
from
gifttable p
where p.giftdate >=@Giftdatep
and p.giftdate <=@Giftdatep
and p.gifttype = ('p')