/// <summary> /// This is a helper method that generates an if statement that checks the batches executed /// table to see if the current batch has been executed. The if statement will look like this /// /// if not exists(select 1 from [tempdb].[dbo].[$(CompletedBatches)] /// where BatchId = batchId) /// begin /// end /// </summary> /// <param name="batchId"></param> /// <returns></returns> private static IfStatement CreateIfNotExecutedStatement(int batchId) { // Create the exists/select statement ExistsPredicate existsExp = new ExistsPredicate(); ScalarSubquery subQuery = new ScalarSubquery(); existsExp.Subquery = subQuery; subQuery.QueryExpression = new QuerySpecification { SelectElements = { new SelectScalarExpression { Expression = new IntegerLiteral{ Value = "1" } } }, FromClause = new FromClause { TableReferences = { new NamedTableReference() { SchemaObject = CreateCompletedBatchesName() } } }, WhereClause = new WhereClause { SearchCondition = new BooleanComparisonExpression { ComparisonType = BooleanComparisonType.Equals, FirstExpression = new ColumnReferenceExpression { MultiPartIdentifier = new MultiPartIdentifier { Identifiers = { CreateIdentifier(BatchIdColumnName, QuoteType.SquareBracket) } } }, SecondExpression = new IntegerLiteral { Value = batchId.ToString() } } } }; // Put together the rest of the statement IfStatement ifNotExists = new IfStatement { Predicate = new BooleanNotExpression { Expression = existsExp } }; return(ifNotExists); }
private List <TableParsingResult> ExtractTablesFromScalarSubQuery(ScalarSubquery scalarSubquery) { List <TableParsingResult> result = new List <TableParsingResult>(); if (scalarSubquery.QueryExpression is QuerySpecification querySpecification) { var items = ExtractTablesFromQuerySpecification(querySpecification); result.AddIfNotExists(items); } return(result); }
public override void Visit(ScalarSubquery node) { this.action(node); }
public override void Visit(ScalarSubquery node) { base.Visit(node); Subqueries.Add(node); }
public override void ExplicitVisit(ScalarSubquery fragment) { _fragments.Add(fragment); }
public gsScalarExpressionParserScalarSubquery(ScalarExpression expression, string columnAlias) : base(expression, columnAlias) { _ScalarExpression = expression as ScalarSubquery; }