List of Date Formats Available with CONVERT() in SQL Server

The following table contains a list of the date formats that you can provide to the CONVERT() function when you convert a date/time value to a string.

These formats are provided as an optional third argument when calling the CONVERT() function. They’re provided as an integer expression that specifies how the CONVERT() function will format the date. 

Continue reading

How to Fix “The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION” in SQL Server

If you’re receiving error Msg 3902, Level 16, which reads “The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION”, it’s probably because you’ve got a stray COMMIT statement.

You could be getting this due to implementing error handling, and forgetting that you’ve already committed or rolled back the transaction elsewhere in your code.

Continue reading

How to Create an Index with a Specific Name in MongoDB

When you create an index in MongoDB, if you don’t specify a name for it, MongoDB will assign one.

The default name consists of each indexed field name concatenated with the key value for that field. For example, the sort order, or if it’s a text index, the string _text, or if it’s a 2dsphere index, the string _2dsphere, etc.

But you can assign your own name when creating indexes in MongoDB.

Continue reading

Exclude Specific Fields in Wildcard Index in MongoDB

When you create a wildcard index in MongoDB, you have the option of specifying a single field, all fields, or just some.

You also have the option of excluding certain fields. In other words, you can specify all fields except for one or more specific fields.

You can use the wildcardProjection parameter to include or exclude specific field paths from the wildcard index. This article presents an example of excluding specific fields in the wildcard index.

Continue reading

Create a Multi-Language Text Index in MongoDB

When you create a text index in MongoDB, the index uses a default language of english.

The default language determines the rules to parse word roots (i.e. stemming) and ignore stop words.

However, you can change the default language if required.

You can also specify a language at the document level, and even at the subdocument level. The default language will only be used if a language hasn’t been specified at the document or subdocument level.

This article presents examples of specifying a language for a text index.

Continue reading

Create a Text Index with Different Field Weights in MongoDB

When you create a text index in MongoDB, you have the option of applying different weights to each indexed field.

These weights denote the relative significance of the indexed fields to each other. A field with a higher weight will have more impact in the search results than a field with a lower weight.

This provides you with a certain amount of control over how the search results are calculated.

The default weight is 1, so if you don’t specify a weight for field, it will be assigned a weight of 1.

Continue reading