We receive feeds where some columns have names but the rest go from field2, field3, field4....etc, field230. Not all these fields are filled and the number of filled fields is not known ahead of time.
But we use all fields that contain data!
To avoid the "Select *" I created a dynamic SQL statement and I create the Select part of the query in a loop such as:
Then the Select statement includes all fields and I go on to the build the rest of the query dynamically.
From what I know there are advantages and disadvantages for Select * and dynamic SQL but considering my situation I am not sure if using dynamic is correct. Since I need all the fields maybe I should just use "Select *"?
Can someone please share with me which I should use in this situation and why so I can create the correct stored procedure? This query also uses a UNION.
Much thanks!
But we use all fields that contain data!
To avoid the "Select *" I created a dynamic SQL statement and I create the Select part of the query in a loop such as:
Code:
WHILE @Counter < 230
BEGIN
SET @Fields = @Fields + 'Field' + CAST(@Counter AS VARCHAR(3)) + ', '
SET @Counter = @Counter + 1
END
SET @Fields = SUBSTRING(@Fields, 1, (LEN(@Fields) - 1))
From what I know there are advantages and disadvantages for Select * and dynamic SQL but considering my situation I am not sure if using dynamic is correct. Since I need all the fields maybe I should just use "Select *"?
Can someone please share with me which I should use in this situation and why so I can create the correct stored procedure? This query also uses a UNION.
Much thanks!