Announcement

Collapse
No announcement yet.

Variable within a select query

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Variable within a select query

    I use sql server 2012, I need to do a query like this:
    DECLARE @mag AS INT
    SET @mag=1
    SELECT cm.SegnoMP,cm.SegnoMA,m.CodMagazzinoPartenza,m.Cod MagazzinoArrivo,
    CASE
    WHEN m.CodMagazzinoArrivo=@mag AND m.CodMagazzinoPartenza=@mag THEN CONVERT(INT,cm.SegnoMA+'1')* m.Quantita
    WHEN m.CodMagazzinoPartenza=@mag THEN CONVERT(INT,cm.SegnoMP+'1')* m.Quantita
    WHEN m.CodMagazzinoArrivo=@mag THEN CONVERT(INT,cm.SegnoMA+'1')* m.Quantita
    END AS QT
    FROM Movim m
    LEFT JOIN CauMov cm ON cm.Codice=m.CodCausale
    WHERE (m.CodMagazzinoPartenza=1) OR ( m.CodMagazzinoArrivo=1)

    how can I use a variable @ ... within scriptcase ?.
    I tried it with clobal variable [..] me does not work.

  • #2
    I tried do that with mysql, but the query it breaks constantly, I solved using a view.

    Comment


    • #3
      This is an example or the real code? You can build this select on a string an replace this sql user vars by code.
      $myvalue = 1;
      $sql = ".......CASE
      WHEN m.CodMagazzinoArrivo=$myvalue AND m.CodMagazzinoPartenza=$myvalue THEN
      ....";

      Where are you trying to use it?
      /Giuseppe

      Professional Scriptcase Services
      Some Customers opinions

      Comment

      Working...
      X