I have the following code...
In testing my variable worked fine. But I only had one query.
I find this works if I redefine the variable after each "go".
Is there a way to define the vaiable for the whole script.
I would probably call it a global variable.
Thanks
Uncle Mike
--Get the date from a table and use that for the Billing date
declare @mydate datetime
set @mydate = '9/1/2007'
--set @mydate=(select [BillingDate] from [400_Metafile].[dbo].[BillingDate] WHERE [DateDesc]='Custbills')
print @mydate
-- Update the account Number From the Filename
UPDATE [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
SET [AccountNumber] = left([Filename],10)
WHERE [AccountNumber] is null
GO
print @mydate
-- Update the branch
UPDATE [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
SET [Branch] = substring([filename], CHARINDEX('_',[filename])+1,
CHARINDEX('.',[filename]) - CHARINDEX('_',[filename])-1)
WHERE CHARINDEX('_',[filename])>0 and [branch] is null
GO
print @mydate
--Update the ActBranch where is not null
UPDATE [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
SET [ActBrch] = [Accountnumber] + [Branch]
where [branch] is not null and [ActBrch] is null
Go
print @mydate
--Update the ActBranch where is null
UPDATE [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
SET [ActBrch] = [Accountnumber]
where [branch] is null and [ActBrch] is null
GO
print @mydate
-- Update the Billing Date to the Date to the billing period
print @mydate
UPDATE [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
SET [BillingDate] = @mydate
WHERE [BillingDate] is Null
GO
-- View what we just did
SELECT Filename, AccountNumber, Branch, ActBrch, BillingDate
FROM [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
Where [BillingDate] = @mydate
GO
In testing my variable worked fine. But I only had one query.
I find this works if I redefine the variable after each "go".
Is there a way to define the vaiable for the whole script.
I would probably call it a global variable.
Thanks
Uncle Mike
--Get the date from a table and use that for the Billing date
declare @mydate datetime
set @mydate = '9/1/2007'
--set @mydate=(select [BillingDate] from [400_Metafile].[dbo].[BillingDate] WHERE [DateDesc]='Custbills')
print @mydate
-- Update the account Number From the Filename
UPDATE [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
SET [AccountNumber] = left([Filename],10)
WHERE [AccountNumber] is null
GO
print @mydate
-- Update the branch
UPDATE [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
SET [Branch] = substring([filename], CHARINDEX('_',[filename])+1,
CHARINDEX('.',[filename]) - CHARINDEX('_',[filename])-1)
WHERE CHARINDEX('_',[filename])>0 and [branch] is null
GO
print @mydate
--Update the ActBranch where is not null
UPDATE [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
SET [ActBrch] = [Accountnumber] + [Branch]
where [branch] is not null and [ActBrch] is null
Go
print @mydate
--Update the ActBranch where is null
UPDATE [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
SET [ActBrch] = [Accountnumber]
where [branch] is null and [ActBrch] is null
GO
print @mydate
-- Update the Billing Date to the Date to the billing period
print @mydate
UPDATE [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
SET [BillingDate] = @mydate
WHERE [BillingDate] is Null
GO
-- View what we just did
SELECT Filename, AccountNumber, Branch, ActBrch, BillingDate
FROM [MetaViewer Enterprise].[dbo].[BUG Customer Bills]
Where [BillingDate] = @mydate
GO