I feel really dumb because I could easily do this in java or C# with a for loop but I am new to SQL and I am having trouble figuring this out. What I have so far is that I have declared two integer variables for the numbers I want to find the common factors for. However with SQL from what I am reading I need to use a while loop to cycle throuh the numbers to find the common factors, am I on the right track? After that I just want SQL server to print the common factors. Here is the code I have so far...
DECLARE @num1 int = 10;
DECLARE @num2 int = 20;
DECLARE @count INT = 1;
WHILE @count < @num1
BEGIN
IF (@num % @count = ?)
PRINT 'common factors'
END
Am I at least on the right track here? Thanks in advance for any help