DECLARE C CURSOR FOR
select HQ,[year],
County,tollfree,Acc
from RICHLBD..[Business Classify]
declare @HQ varchar(50)
declare @year varchar(50)
declare @County varchar(50)
declare @tollfree varchar(50)
declare @Acc varchar(50)
OPEN C
FETCH NEXT FROM C INTO @HQ,@year,@County,@tollfree,@Acc
WHILE @@FETCH_STATUS =0
BEGIN
UPDATE T_Company_temp
SET OfficeClassification=@HQ,
YearOfEstablishment=@year,
County=@County,
TollFree=@tollfree
WHERE CompanyID=@Acc
FETCH NEXT FROM C INTO @HQ,@year,@County,@tollfree,@Acc
END
CLOSE C
DEALLOCATE C
Nov 25, 2008
Nov 24, 2008
website viewcount in sqlserver 2005
USE [RICHSNBD]
GO
/****** Object: StoredProcedure [dbo].[UpdateUser_viewcount] Script Date: 11/24/2008 15:57:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/* *****************************************************************************
Procedure : [UpdateUser_viewcount]
Function / Purpose : To update viewcount column of particular table
Trigger : No
Name of Author(s) : Ambikapathi
Start Date : Nov/22/2008
Tables involved : SubscriberLevel
Table Name : T_SubscriberLevel
#No. Modified By Modification Date :
Purpose :
*****************************************************************************
*/
CREATE PROCEDURE [dbo].[UpdateUser_viewcount]
@UserID UNIQUEIDENTIFIER
AS
DECLARE @Msg nvarchar(100)
DECLARE @RowCount int
DECLARE @Error int
DECLARE @view_count int
-- First check the user id is valid --
-- select view count from --
SELECT @view_count=view_count
FROM T_SubscriberLevel
where UserID=@UserID and
SubscriptionLevel=7
SELECT @Error = @@ERROR, @RowCount = @@ROWCOUNT
IF @Error != 0 OR @RowCount = 0
BEGIN
SET @Msg = ''
RAISERROR(@Msg,16,1)
RETURN 0
END
-- Have a valid User Id, so Update User Details -
UPDATE T_SubscriberLevel
SET view_count = @view_count+1
WHERE UserID = @UserID
SELECT @Error = @@ERROR, @RowCount = @@ROWCOUNT
IF @Error != 0 OR @RowCount = 0
BEGIN
SET @Msg = 'Unable to update user view count detail'
RAISERROR(@Msg,16,1)
RETURN 0
END
SELECT view_count
FROM T_SubscriberLevel
WHERE UserID = @UserID
RETURN 1
-- EXEC UpdateUser_viewcount 'e49273fd-7832-4365-b3ce-02221f58ebf4'
GO
/****** Object: StoredProcedure [dbo].[UpdateUser_viewcount] Script Date: 11/24/2008 15:57:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/* *****************************************************************************
Procedure : [UpdateUser_viewcount]
Function / Purpose : To update viewcount column of particular table
Trigger : No
Name of Author(s) : Ambikapathi
Start Date : Nov/22/2008
Tables involved : SubscriberLevel
Table Name : T_SubscriberLevel
#No. Modified By Modification Date :
Purpose :
*****************************************************************************
*/
CREATE PROCEDURE [dbo].[UpdateUser_viewcount]
@UserID UNIQUEIDENTIFIER
AS
DECLARE @Msg nvarchar(100)
DECLARE @RowCount int
DECLARE @Error int
DECLARE @view_count int
-- First check the user id is valid --
-- select view count from --
SELECT @view_count=view_count
FROM T_SubscriberLevel
where UserID=@UserID and
SubscriptionLevel=7
SELECT @Error = @@ERROR, @RowCount = @@ROWCOUNT
IF @Error != 0 OR @RowCount = 0
BEGIN
SET @Msg = ''
RAISERROR(@Msg,16,1)
RETURN 0
END
-- Have a valid User Id, so Update User Details -
UPDATE T_SubscriberLevel
SET view_count = @view_count+1
WHERE UserID = @UserID
SELECT @Error = @@ERROR, @RowCount = @@ROWCOUNT
IF @Error != 0 OR @RowCount = 0
BEGIN
SET @Msg = 'Unable to update user view count detail'
RAISERROR(@Msg,16,1)
RETURN 0
END
SELECT view_count
FROM T_SubscriberLevel
WHERE UserID = @UserID
RETURN 1
-- EXEC UpdateUser_viewcount 'e49273fd-7832-4365-b3ce-02221f58ebf4'
Nov 19, 2008
XML output in sqlserver 2005
SELECT 1 AS TAG,
NULL AS PARENT,
NULL AS [ROOT!1],
NULL AS [TABLE!2],
NULL AS [FIELDS!3!ertr],
NULL AS [FIELDS!3!rtr]
UNION ALL
SELECT 2 AS TAG,
1 AS PARENT,
NULL,
'TEMP',
NULL,
NULL
UNION ALL
SELECT 3 AS TAG,
2 AS PARENT,
NULL,
NULL,
RTRIM(ERTR),
RTRIM(RTR)
from temp
FOR XML EXPLICIT
NULL AS PARENT,
NULL AS [ROOT!1],
NULL AS [TABLE!2],
NULL AS [FIELDS!3!ertr],
NULL AS [FIELDS!3!rtr]
UNION ALL
SELECT 2 AS TAG,
1 AS PARENT,
NULL,
'TEMP',
NULL,
NULL
UNION ALL
SELECT 3 AS TAG,
2 AS PARENT,
NULL,
NULL,
RTRIM(ERTR),
RTRIM(RTR)
from temp
FOR XML EXPLICIT
craeteing temp table in sqlserver 2005
CREATE TABLE #names_sample (
name_id INT IDENTITY(1, 1) NOT NULL,
company_id varchar(50),
full_name VARCHAR(110) NULL,
first_name VARCHAR(50) NULL,
middle_name VARCHAR(50) NULL,
last_name VARCHAR(30) NULL,
suffix VARCHAR(20) NULL
)
name_id INT IDENTITY(1, 1) NOT NULL,
company_id varchar(50),
full_name VARCHAR(110) NULL,
first_name VARCHAR(50) NULL,
middle_name VARCHAR(50) NULL,
last_name VARCHAR(30) NULL,
suffix VARCHAR(20) NULL
)
sql case statement with selecting records.
select case
when len(id)=5 then 'CO'+'000'+cast(id as varchar(5))
when len(id)=6 then 'CO'+'00'+cast(id as varchar(6))
when len(id)=7 then 'CO'+'0'+cast(id as varchar(7))
end,ContactPosition,CompanyID
from contact_id_temp
when len(id)=5 then 'CO'+'000'+cast(id as varchar(5))
when len(id)=6 then 'CO'+'00'+cast(id as varchar(6))
when len(id)=7 then 'CO'+'0'+cast(id as varchar(7))
end,ContactPosition,CompanyID
from contact_id_temp
Subscribe to:
Posts (Atom)