While drag-drop a stored procedure in dbml file I get this error:
Unknown Return Type
The return types for the following stored
You might as well consider using CONCAT() method instead of '+' to concat a string. Since I wasn't using temp table and yet still encounter this problem. I found out that concating strings using '+' triggering this.
In my case, I was using this:
SET @errorMessage = CONCAT('Update (ID=', @pnID, ') failed. Name already exists.');
Instead of:
SET @errorMessage = 'Update (ID=' + @pnID + ') failed. Name already exists.';
Reason: Your Stored Procedure will be returning a complex type. that is, multiple results or uses a temp table.
Resolution
It entirely depends on what your Stored Procedure is doing. Useful links
I also had the problem (VS 2012, SQL Server 2008R2). In my case it was a combination of the +
operator and various CAST
statements in the code. I haven't found a way to replace them with something VisualStudio likes, but I have come up with a workaround:
Workaround "Dummy SELECT":
select 'bla bla' as field1, 123123 as field2, 'asñfs' as field3
The solution I found ... I put a SELECT on top (IF) with conditions that are not correct and create a variable table with the result he wanted to exit and then "ELSE" put things right. The first part is only if you understand the process output I want. Look at my example
ALTER PROCEDURE [dbo].[SS_getSearchedProductsDetailsNew]
(
@mk int,
@md int,
@yr int = 0,
@caroption int = 0,
@condition int = 0,
@producttype int = 0 ,
@option int = 0,
@coloroption int = 0
)
AS
declare @sql nvarchar(max)
Begin
if @mk = 0 and @md = 0 and @yr = 0
begin
Declare @TempTable2 TABLE(
ProductID numeric(10),
TypeName nvarchar(50),
MakeID numeric(10),
ModelID numeric(10),
ConditionID numeric(10),
CarOptionsID numeric(10),
OptionsID numeric(10),
ColorOptionsID numeric(10),
Make nvarchar(50),
Model nvarchar(50),
YearID numeric(5),
Color nvarchar(50),
ProductType nvarchar(50),
CarOptionName nvarchar(50),
OptionName nvarchar(50),
ColorOptionName nvarchar(50),
ConditionName nvarchar(50),
Notes nvarchar(500),
Price money,
cog money)
select * from @TempTable2
end
else
begin
select @sql = '
declare @theNotes nvarchar(500)
declare @theMake numeric(10), @theModel numeric(10), @theYear numeric(10)
declare @makeName nvarchar(50), @modelName nvarchar(50), @ID numeric(5)
declare @theProductType nvarchar(50), @theTypeName nvarchar(50)
declare @theColor nvarchar(50),@theProductID numeric(10)
declare @theCondition numeric(10),@theCarOption numeric(10) , @theOption numeric(10), @theColorOption numeric(10)
declare @theConditionName nvarchar(50),@theCarOptionName nvarchar(50), @theOptionName nvarchar(50),@theColorOptionName nvarchar(50)
declare @thePrice money, @theCog money
declare @HoldingTable table(
ID numeric identity,
ProductID numeric(10),
MakeID numeric(10),
ModelID numeric(10),
ConditionID numeric(10),
CarOptionsID numeric(10),
OptionsID numeric(10),
ColorOptionsID numeric(10),
Make nvarchar(50),
Model nvarchar(50),
YearID numeric(5),
Color nvarchar(50),
ProductType nvarchar(50),
Notes nvarchar(500),
Price money,
cog money);
INSERT INTO @HoldingTable (ProductID,MakeID, ModelID , ConditionID, CarOptionsID,OptionsID,ColorOptionsID, Make ,Model,YearID,Color, ProductType, Notes, Price, cog)
SELECT
ProductNumber as ProductID,
tblProductsForSale.MakeID as MakeID,
tblProductsForSale.ModelID as ModelID ,
ConditionID,
CarOptionsID,
OptionsID,
ColorOptionsID,
tblVehicleMake.Make as Make ,
tblVehicleModel.Model as Model,
YearID,
Color,
ProductType, Notes,
tblProductsForSale.ResalePrice as Price,
tblProductsForSale.SellPrice as cog
from tblProductsForSale, tblVehicleMake, tblVehicleModel where
tblProductsForSale.MakeID = tblVehicleMake.MakeID and
tblProductsForSale.ModelID = tblVehicleModel.ModelID
and tblProductsForSale.ProductStatus=''available'' and tblProductsForSale.Custom=0'
if(@mk > 0)
begin
select @sql = @sql + ' and tblProductsForSale.MakeID = ' + convert(varchar, @mk)
end
if @md > 0
Begin
select @sql = @sql + ' and tblProductsForSale.ModelID = ' + convert(varchar, @md)
End
if @yr > 0
begin
select @sql = @sql + ' and tblProductsForSale.YearID = ' + convert(varchar, @yr)
end
if @caroption > 0
begin
select @sql = @sql + ' and tblProductsForSale.CarOptionsID = ' + convert(varchar, @caroption)
end
if @producttype > 0
begin
select @sql = @sql + ' and tblProductsForSale.ProductType = ''' + convert(varchar,@producttype) + ''''
end
if @option > 0
begin
select @sql = @sql + ' and tblProductsForSale.OptionsID = ' + convert(varchar, @option)
end
if @coloroption > 0
begin
select @sql = @sql + ' and tblProductsForSale.ColorOptionsID = ' + convert(varchar, @coloroption)
end
--select @sqlInsert = 'INSERT INTO @HoldingTable (ProductID,MakeID, ModelID , ConditionID, CarOptionsID,OptionsID,ColorOptionsID, Make ,Model,YearID,Color, ProductType, Price, cog) '
--select @sqlExec = @sqlInsert + @sql
--select * from @HoldingTable
select @sql = @sql + 'Declare @TempTable2 TABLE(
ProductID numeric(10),
TypeName nvarchar(50),
MakeID numeric(10),
ModelID numeric(10),
ConditionID numeric(10),
CarOptionsID numeric(10),
OptionsID numeric(10),
ColorOptionsID numeric(10),
Make nvarchar(50),
Model nvarchar(50),
YearID numeric(5),
Color nvarchar(50),
ProductType nvarchar(50),
CarOptionName nvarchar(50),
OptionName nvarchar(50),
ColorOptionName nvarchar(50),
ConditionName nvarchar(50),
Notes nvarchar(500),
Price money,
cog money)
WHILE Exists(Select * from @HoldingTable )
begin
Select @ID = ID FROM @HoldingTable
Select @theProductId = ProductID from @HoldingTable
Select @theMake = MakeID from @HoldingTable
Select @theModel = ModelID from @HoldingTable
Select @theCondition = ConditionID from @HoldingTable
Select @theCarOption = CarOptionsID from @HoldingTable
Select @theOption = OptionsID from @HoldingTable
Select @theColorOption = ColorOptionsID from @HoldingTable
Select @theYear = YearID from @HoldingTable
Select @theColor = Color from @HoldingTable
Select @theProductType = ProductType from @HoldingTable
Select @theTypeName = TypeName from tblProductType WHere ProductTypeID = cast (@theProductType as numeric(10))
Select @thePrice = Price from @HoldingTable
Select @theCog = cog from @HoldingTable
Select @theConditionName = ConditionName from tblConditions Where ConditionID = @theCondition
Select @makeName = Make from tblVehicleMake Where MakeID = @theMake
Select @modelName = Model from tblVehicleModel Where ModelID = @theModel
Select @theCarOptionName = CarOptionsName from tblCarOptions Where CarOptionsID = @theCarOption
Select @theOptionName = OptionsName from tblOptions Where OptionsID = @theOption
Select @theColorOptionName = ColorOptionsName from tblColorOptions Where ColorOptionsID = @theColorOption
Select @theNotes = Notes from @HoldingTable
Select @theProductType = ProductType from @HoldingTable
INSERT INTO @TempTable2 (ProductID,TypeName,MakeID,ModelID,ConditionID ,CarOptionsID,OptionsID ,ColorOptionsID ,Make , Model , YearID ,Color, ProductType, CarOptionName ,OptionName,ColorOptionName ,ConditionName, Notes, Price, cog)
VALUES (@theProductId,@theTypeName, @theMake, @theModel, @theCondition, @theCarOption,@theOption,@theColorOption, @makeName,@modelName, @theYear, @theColor,@theProductType, @theCarOptionName, @theOptionName, @theColorOptionName, @theConditionName, @theNotes, @thePrice , @theCog )
DELETE FROM @HoldingTable Where ID = @ID
end
Select * from @TempTable2 order by ProductID '
end
exec ( @sql )
End
I also had this problem - had to comment out code that was constructing a polygon:
declare
@MapBounds geography
;
select
@MapBounds = geography::STGeomFromText('POLYGON((' +
cast(@NorthEastLng as varchar) + ' ' + cast(@NorthEastLat as varchar) + ', ' +
cast(@SouthWestLng as varchar) + ' ' + cast(@NorthEastLat as varchar) + ', ' +
cast(@SouthWestLng as varchar) + ' ' + cast(@SouthWestLat as varchar) + ', ' +
cast(@NorthEastLng as varchar) + ' ' + cast(@SouthWestLat as varchar) + ', ' +
cast(@NorthEastLng as varchar) + ' ' + cast(@NorthEastLat as varchar) +
'))', 4326)
;
Once it was added to the dmbl, I un-commented out the code and it worked like a champ!
I've struggled a lot on this and came to conclusion, that if your stored procedure is dynamic and is combined with strings you sometimes miss something.. so while importing Visual Studio DBML import/update can not execute/test the procedure, so return type stays undefined, once you correct the procedure (query strings that you are building up to execute) you can add the procedure without any problems.