Firstly, Like the new look, very nice!
I have a table [dbo].[tbl_Discharge] with a column call [Ward] at the moment the column contains data like F1*WSH and PACU*WSH etc, I am trying to update the column data to all char to the left of the * (* appears in different posistions)
I only want to carry out this update on rows where [download_date] is > Date()
Here's where I'm at so far but it's not working to well, I was using the PRINT function to display the results before I commit to executing the code on the actual data.
Code:Declare @NewWard nvarchar(15), @Ward nvarchar(15), @Date datetime, @Len int, @i int SET @Ward = (SELECT [Ward] From [dbo].[tbl_Discharge] WHERE [Download_Date] >= DATEDIFF(dd,0,GETDATE())) SET @Date = DATEDIFF(dd,0,GETDATE()) SET @i = 0 SET @Len = Len(@Ward) While @i < @Len + 1 If Right(Left(@Ward,@i),1) = '*' SET @NewWard = Left(@Ward,@i-1) PRINT 'Old Ward Name = ' + @Ward + ', new ward name = ' + @NewWard + ', Download Date = ' @Date SET @i = @i + 1 GO