SQL Generic Script

Source: Internet
Author: User

1. When restoring data, culling takes:

ALTER DATABASE golf7_jhw SET OFFLINE with ROLLBACK IMMEDIATE

ALTER Database GOLF7_JHW Set Online

2. query table field Description sql:

SELECT Objname,value from:: Fn_listextendedproperty (NULL, ' user ', ' dbo ', ' table ', ' name ', ' column ', default)

4. Querying for duplicate data
For example: SELECT * FROM dbo. T_club WHERE Clubcode in (SELECT clubcode from dbo. T_club GROUP by Clubcode have COUNT (*) > 1)

5. Only one bar is displayed when duplicate data is queried
For example: SELECT * FROM dbo. T_club WHERE clubid in (SELECT MAX (clubid) from dbo. T_club GROUP by Clubcode)

3. Dynamic SQL Script (SP):

--=======================================================
--created By:yzh
--created date:2015-12-31
--description: View Member Benefits
--test:exec p_getequityplaynum ' F2015 ', 11
--=======================================================
ALTER proc [dbo]. [P_getequityplaynum]
(
@MembershipCardNo varchar (200)
, @ClubID int
)
As
Begin
declare @sqlStr nvarchar (max)
Set @sqlStr = '
Select
Clubid
, Regioninnerweekdaynumber
, Regioninnerholidaynumber
, Limitregioninnernumber
, Regionouterweekdaynumber
, Regionouterholidaynumber
, Limitregionouternumber
From T_equityplaynum E
Inner join t_membership m on e.membertype = M.membershiptypeid '
--Ball Club ID
If not (@ClubID is null or @ClubID =0)
Begin
Set @sqlStr = @sqlStr + case if charindex (' where ', @sqlStr) > 0 Then ' and ' Else ' WHERE ' end;
Set @[email protected] + ' E.clubid = ' + Convert (varchar, @ClubID);
End
--Membership card number
If not (@MembershipCardNo is null or @MembershipCardNo = ')
Begin
Set @sqlStr = @sqlStr + case if charindex (' where ', @sqlStr) > 0 Then ' and ' Else ' WHERE ' end;
Set @[email protected]+ ' M.membershipcardno = ' + @MembershipCardNo + ';
End
--print @sqlStr
EXEC sp_executesql @sqlStr
End

GO

SQL Generic Script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.