SQL multi-conditional query stitching string changed to normal query format

Source: Internet
Author: User

SetAnsi_nulls onSetQuoted_identifier onGoALTER PROC [dbo].[Usp_srv_checkservicedemandorder]@AInsNO NVARCHAR( -)=NULL,--must fill in@ACompanyName NVARCHAR( -)= NULL,--must fill in@ADepartmentName NVARCHAR( -)= NULL,@AName NVARCHAR( -)= NULL,--must fill in@ApplicantID NVARCHAR( -)= NULL,@APhone VARCHAR( -)= NULL,--Telephone@ACellPhone VARCHAR( -)= NULL,--Mobile Phone@AEmail VARCHAR( -)= NULL, @AFax NVARCHAR( -)= NULL,@AcceptWay TINYINT= NULL,@OneLevelSortID INT= NULL,@TwoLevelSortID INT= NULL,@ThreeLevelSortID INT= NULL,@LogContent NVARCHAR(MAX)= NULL as/*PAGE:Action:CreatedBy:CreatedDate:ModifiedHistory:Test scripts:declare @return_value intexec @return_value = [D Bo]. [Usp_srv_checkservicedemandorder] @AInsNO = n ' 00010000 ', @LogContent = N ' Day ' SELECT ' Return Value ' = @return_valueGO */ SETNOCOUNT onSELECT *  fromTbl_servicedemandorderWHERE(@AInsNO  is NULL    ORAinsno= @AInsNO )  and(@ACompanyName  is NULL    ORAcompanyname= @ACompanyName ) and(@ADepartmentName  is NULL   ORAdepartmentname= @ADepartmentName ) and(@AName  is NULL   ORAName= @AName ) and(@ApplicantID  is NULL   ORApplicantid= @ApplicantID ) and(@APhone  is NULL   ORAphone= @APhone ) and(@ACellPhone  is NULL   ORAcellphone= @ACellPhone ) and(@AEmail  is NULL   ORAemail= @AEmail ) and(@AFax  is NULL   ORAfax= @AFax ) and(@AcceptWay  is NULL   ORAcceptway= @AcceptWay ) and(@OneLevelSortID  is NULL   OROnelevelsortid= @OneLevelSortID ) and(@TwoLevelSortID  is NULL   ORTwolevelsortid= @TwoLevelSortID ) and(@ThreeLevelSortID  is NULL   ORThreelevelsortid= @ThreeLevelSortID ) and((@LogContent  is NULL)OR(ISNULL(Logcontent,"') like '%'+ISNULL(@LogContent,"')+'%'))----declare @tmpTable TABLE ()--DECLARE @sqlStr VARCHAR (MAX)--SET @sqlStr = '--SELECT * from Dbo.tbl_servicedemandorder--WHERE Ainsno = ' + @AInsNO--+ ' and acompanyname like and AName = ' ' + @AName + '--   --IF (Nullif (@ADepartmentName, ') is not null)--BEGIN--SET @sqlStr = @sqlStr + ' and adepartmentname = ' ' + @ADepartmentName + ' "--END--IF (Nullif (@ApplicantID, ') is not null)--BEGIN--SET @sqlStr = @sqlStr + ' and Applicantid = ' ' + @ApplicantID + ' "--END--IF (Nullif (@APhone, ') is not null)--BEGIN--SET @sqlStr = @sqlStr + ' and Aphone = ' ' + @APhone + ' "--END--IF (Nullif (@ACellPhone, ') is not null)--BEGIN--SET @sqlStr = @sqlStr + ' and Acellphone = ' ' + @ACellPhone + ' "--END--IF (Nullif (@AEmail, ') is not null)--BEGIN--SET @sqlStr = @sqlStr + ' and Aemail = ' ' + @AEmail + ' "--END--IF (Nullif (@AFax, ') is not null)--BEGIN--SET @sqlStr = @sqlStr + ' and Afax = ' ' + @AFax + ' "--END--IF (Nullif (@ReqDescription, ') is not null)--BEGIN--SET @sqlStr = @sqlStr + ' and reqdescription = ' ' + @ReqDescription + ' "--END--EXEC (@sqlStr)SETNOCOUNTOFF

SQL multi-conditional query stitching string changed to normal query format

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.