Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi All,

I want to store all rows values of particular column in SQL

What I have tried:

SQL
declare @a int
declare @b int

set @a= select Stock from ABC
set @b= select month from ABC

And use loop for further calculation 

while @i< 12
if @a > b 
return @a
@i=@i+1
Posted
Updated 10-Jan-18 17:04pm
v2

If you want to return Stock and [month] columns with some criteria, try this:

SQL
SELECT Stock, [month]
FROM ABC
WHERE Stock > [month]
 
Share this answer
 
DECLARE @a INT,@b INT,@c INT=0;
DECLARE @ABC TABLE(id INT identity(1,1),stock int,month INT);
BEGIN
   INSERT INTO @ABC(Stock,month) SELECT Stock,Month FROM ABC;

    WHILE @c<=(SELECT COUNT(1) FROM @ABC)

     BEGIN
       SELECT @a=Stock,@b=month FROM @ABC WHERE ID=@c;
        if @a>@b 

         SELECT @a;
          ELSE 
         SELECT @b;

      SET @c=@c+1;
     END;
END;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900