Edit: HAS to be saved by proc, NOT a function , sorry!
I have a table:
TABLE: dbo.Numbers
Number_ID | Number
1 | 0
2 | 1
3 | 2
4 | 3
5 | 4
6 | 5
7 | 6
8 | 7
I need the following output ( as a view ):
Number_ID | ModifiedNumber
1 | lol the num is 0
2 | lol the num is 1
3 | lol the num is 2
4 | lol the num is 3
5 | lol the num is 4
6 | lol the num is 5
7 | lol the num is 6
8 | lol the num is 7
I have a stored procedure for this:
CREATE PROCEDURE dbo.UselessStoredProc @inputNum int
AS
SELECT 'lol my number is: ' + CONVERT(varchar(max), @inputNum)
GO
EXEC dbo.UselessStoredProc @inputNum=2;
My ultimate goal is to populate ModifiedNumbercol through a saved process, for example:
SELECT Number_ID, EXEC UselessStoredProc @inputNum = Number_ID as ModifiedNumber
FROM [TestDb].[dbo].[Numbers]
Obviously this does not work. How to do it.
PS Please don't tell me "just:
SELECT Number_ID, 'lol my number is: ' + CONVERT(varchar(max), Number_ID) as ModifiedNumber
FROM [TestDb].[dbo].[Numbers]
"
I know well that I can do this - this is obviously an example, the real code is much more complicated and requires a MEMORED PROCEDURE . Note that I intentionally return a string from a sample stored procedure - I need complex values, not just that int.
Edit:
SQL Server 2012
. . "" , .
2: , SP, , , , SQL. , , , :
DECLARE @sql nvarchar(max) = 'SELECT @Data_Table_Key = COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE OBJECTPROPERTY(OBJECT_ID(CONSTRAINT_SCHEMA + ''.'' + QUOTENAME(CONSTRAINT_NAME)), ''IsPrimaryKey'') = 1 AND TABLE_NAME = ''' + @Data_Table_Name + ''''
EXECUTE sp_executesql @sql, N'@Data_Table_Key varchar(200) OUTPUT', @Data_Table_Key OUTPUT
Edit: , -, openrowset, , . , 5 , . . , , , , .