I have this stored procedure and I want to find a way so that I wouldn't need to provide columns names at all while executing Crates_GetForUser
ALTER procedure [dbo].[GetSomething]
(
@UserID VARCHAR(200),
@URLFilter varchar(256)
)
AS
--Temp table definition must match the output from the Crates_GetForUser stored procedure
CREATE TABLE #CratesTemp
(
ID int,
Title nvarchar(255),
URL nvarchar(255),
CrateID int,
AESKey varchar(100),
UserIsBuyer int,
ClientID int,
PromotionName nvarchar(255),
DisablePrinting bit,
DisableEmailing bit
)
INSERT #CratesTemp (ID, Title, URL, CrateID,AESKey, UserIsBuyer, ClientID, PromotionName, DisablePrinting, DisableEmailing)
EXEC Crates_GetForUser @UserID, @URLFilter
SELECT #CratesTemp.ClientID, #CratesTemp.CrateID, #CratesTemp.ID AS AutoID, Fruits.* FROM Fruits
JOIN #CratesTemp ON Fruits.ListUrl LIKE #CratesTemp.URL + '%' OR Fruits.SiteUrl LIKE #CratesTemp.URL + '%'
Also is it best practice to use this when you can easily use C# code to call the existing stored procedure and then create a new stored procedure to get common stuff.
To me above looks like a SQL code smell, (not developed by me..)
Edit
Maybe I can use Select into but I don't want to provide SQL server or database name at all. THanks, can I do something like this, as I am getting syntax errors,