# Scalar value function broke :(

**URL:** https://forum.kirupa.com/t/scalar-value-function-broke/218937
**Category:** Uncategorized
**Created:** [March 12, 2007, 4:43pm UTC](https://forum.kirupa.com/t/scalar-value-function-broke/218937 "2007-03-12T16:43:43Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![broneah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/broneah/32/1000_2.png) [@broneah](https://forum.kirupa.com/u/broneah)
#### Post date: [March 12, 2007, 4:43pm UTC](https://forum.kirupa.com/t/scalar-value-function-broke/218937/1 "2007-03-12T16:43:43Z")

</div>

[SIZE=2][COLOR=#0000ff]set[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ANSI\_NULLS[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ON[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]set[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]QUOTED\_IDENTIFIER[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ON[/COLOR][/SIZE]  
[SIZE=2]GO[/SIZE]  
[SIZE=2][COLOR=#008000]-- =============================================[/COLOR][/SIZE]  
[SIZE=2][COLOR=#008000]-- Author: \<Ryan Roberts\>[/COLOR][/SIZE]  
[SIZE=2][COLOR=#008000]-- Create date: \<3-09-07\>[/COLOR][/SIZE]  
[SIZE=2][COLOR=#008000]-- Description: \<Returns product image url for product search based on prefered child sku in department.\>[/COLOR][/SIZE]  
[SIZE=2][COLOR=#008000]-- =============================================[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]ALTER[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]FUNCTION[/COLOR][/SIZE][SIZE=2] [dbo][/SIZE][SIZE=2][COLOR=#808080].[/COLOR][/SIZE][SIZE=2][fn\_ProductImageURL][/SIZE]  
[SIZE=2][COLOR=#808080]([/COLOR][/SIZE]  
[SIZE=2][COLOR=#008000]-- Add the parameters for the function here[/COLOR][/SIZE]  
[SIZE=2]@Sku [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2]COLOR=#808080[/COLOR][/SIZE]  
[SIZE=2][COLOR=#808080])[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]RETURNS[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2]COLOR=#808080[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]AS[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]BEGIN[/COLOR][/SIZE]  
[SIZE=2][COLOR=#008000]-- Declare the return variable[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]DECLARE[/COLOR][/SIZE][SIZE=2] @ResultVar [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2]COLOR=#808080[/COLOR][/SIZE]  
[SIZE=2][COLOR=#008000]-- Add the T-SQL statements to compute the return value here[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]IF[/COLOR][/SIZE][SIZE=2][COLOR=#808080]([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]SELECT[/COLOR][/SIZE][SIZE=2] PreferredChildSku [/SIZE][SIZE=2][COLOR=#0000ff]FROM[/COLOR][/SIZE][SIZE=2] product\_HeaderDepartment [/SIZE][SIZE=2][COLOR=#0000ff]WHERE[/COLOR][/SIZE][SIZE=2] ProductSku [/SIZE][SIZE=2][COLOR=#808080]=[/COLOR][/SIZE][SIZE=2] @Sku[/SIZE][SIZE=2][COLOR=#808080])[/COLOR][/SIZE][SIZE=2][COLOR=#808080]!=[/COLOR][/SIZE][SIZE=2][COLOR=#808080]NULL[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]BEGIN[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]SELECT[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]top[/COLOR][/SIZE][SIZE=2]COLOR=#808080[/COLOR][/SIZE][SIZE=2] @ResultVar [/SIZE][SIZE=2][COLOR=#808080]=[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]’~/App\_Common/Images/Products/’[/COLOR][/SIZE][SIZE=2][COLOR=#808080]+[/COLOR][/SIZE][SIZE=2][COLOR=#ff00ff]REPLACE[/COLOR][/SIZE][SIZE=2]COLOR=#808080[/COLOR][/SIZE][SIZE=2][COLOR=#808080]+[/COLOR][/SIZE][SIZE=2][COLOR=#ff0000]’\_sm.jpg’[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]FROM[/COLOR][/SIZE][SIZE=2] product\_HeaderDepartment[/SIZE]  
[SIZE=2][COLOR=#0000ff]WHERE[/COLOR][/SIZE][SIZE=2] ProductSku [/SIZE][SIZE=2][COLOR=#808080]=[/COLOR][/SIZE][SIZE=2] @Sku[/SIZE]  
[SIZE=2][COLOR=#0000ff]END[/COLOR][/SIZE]

[SIZE=2][COLOR=#0000ff]ELSE[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]BEGIN[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]SELECT[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]top[/COLOR][/SIZE][SIZE=2]COLOR=#808080[/COLOR][/SIZE][SIZE=2] @ResultVar [/SIZE][SIZE=2][COLOR=#808080]=[/COLOR][/SIZE][SIZE=2] ImageFileSmall[/SIZE]  
[SIZE=2][COLOR=#0000ff]FROM[/COLOR][/SIZE][SIZE=2] product\_Header[/SIZE]  
[SIZE=2][COLOR=#0000ff]WHERE[/COLOR][/SIZE][SIZE=2] ProductSku [/SIZE][SIZE=2][COLOR=#808080]=[/COLOR][/SIZE][SIZE=2] @sku [/SIZE]  
[SIZE=2][COLOR=#0000ff]END[/COLOR][/SIZE]  
[SIZE=2][COLOR=#0000ff]RETURN[/COLOR][/SIZE][SIZE=2] @ResultVar[/SIZE]  
[SIZE=2][COLOR=#0000ff]END[/COLOR][/SIZE]

why isnt this working? ☹
