I'm tryin to create a view but I'm using a variable to use in an union with other view, but I can't create the view properly.
My code is the this one:
CREATE VIEW QRFACTNCNETA2 AS
DECLARE @IVA INT
SET @IVA=0
SELECT
DOCUMENTO=
CASE
WHEN D.SERIE='N' THEN 'Nota de Credito'
WHEN D.SERIE='NR' THEN 'Nota de Credito'END,
CONCAT(d.SERIE,'-',d.NNOT) AS NO_DOCUMENTO,
d.FECHA,-d.SUBTOTAL AS SUBTOTAL,
IVA AS IVA,
IVA AS IVAMN,
d.TC,
d.MONEDA,(-D.SUBTOTAL*D.TC) AS SUBTOTALMN,
d1.NOCLIENTE,
d1.RAZONSOCIAL,
d2.NOVENDEDOR,
d2.NOMBRE
FROM
dbo.NOTAS d
INNER JOIN dbo.CLIENTES d1 ON (d.CLIENTE=d1.NOCLIENTE)
INNER JOIN dbo.VENDEDOR d2 ON (d1.NOVENDEDOR=d2.NOVENDEDOR)
WHERE D.NNOT NOT LIKE '0' AND (D.APLICADA=1 OR D.SALDO>0)
I'm using the variable twice time, because in the other view I have 2 type of IVA (normal IVA and IVAMN)
I read that I can use a procedure or a parameter, but I can't get it well, In other example I saw this one, but I can't addapted it to mine:
CREATE view v_variables
AS
Declare@b DATE
SET @B=CAST(DATEADD(DD,-7,GETDATE()) AS DATE)
SELECT *
FROM VIEWTABLE
WHERE NAMEDATE>=@b
And they addapted it as this way:
CREATE VIEW v_variables
AS
WITH dts AS(
SELECT CAST(DATEADD(DD,-7,GETDATE()) AS DATE) AS P)
SELECT V.NAME
,V.NAMEDATE
FROM VIETABLE V
CROSS APLY dts d
WHERE V.NAMEDATE>=d.P
I tried to apply on my own code, but I can't do it, because I didn't know what put inter the "SELECT CAST" if I need the variable equals 0.
Can anybody help me or guide me how I have to do it, please?
The more I read about Tesla and their continued nonchalant attitude when it comes to user safety and privacy, my list of reasons to stay clear of them just keeps on growing. As someone who used to wish for a Tesla as their first vehicle, man, am I ever so grateful I've never purchased any of them...
Hilariously enough this joke of a made-up phone gets work. People discovered in the fine print that the $100 preorder deposit for it is non-refundable. Also, if the phone's price is changed - to say $999, instead of $499 - your deposit is STILL non-refundable and you are still expected to pay that full price upon release. EVEN WORSE - IF THE PHONE IS CANCELLED/NEVER RELEASED AT ALL, you are STILL without your $100 deposit!!!
Trump is what a poor man thinks of as rich. (though I guess now with all the bribes and grifting he's got to be a real billionaire now, sigh)
Much like Elon is a dumb man's example of smart.
Question
tetsu-kun
Hey guys.
I'm tryin to create a view but I'm using a variable to use in an union with other view, but I can't create the view properly.
My code is the this one:
I'm using the variable twice time, because in the other view I have 2 type of IVA (normal IVA and IVAMN)
I read that I can use a procedure or a parameter, but I can't get it well, In other example I saw this one, but I can't addapted it to mine:
And they addapted it as this way:
I tried to apply on my own code, but I can't do it, because I didn't know what put inter the "SELECT CAST" if I need the variable equals 0.
Can anybody help me or guide me how I have to do it, please?
Sorry for my poor englis.
Regads.
Edited by tetsu-kunLink to comment
https://www.neowin.net/forum/topic/1397415-sql-server-2012-create-view-with-variables/Share on other sites
1 answer to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now