What?
A very quick note in case I forget this one. If you are trying to join two tables and receiving the error "Conversion failed when converting the varchar value 'B110' to data type int" then read ...
... TRIGGER IF EXISTS incrementUrlAlias;
DELIMITER |
CREATE TRIGGER incrementUrlAlias BEFORE INSERT ON my_table_name
FOR EACH ROW BEGIN
declare original_url varchar(255);
declare url_counter int;
...
... start with a function that just converts a string of words delimited by spaces to a table:
CREATE FUNCTION dbo.[ufn_StringToTable]
(
@StringInput VARCHAR(MAX)
)
RETURNS @OutputTable TABL ...
... words that you want in a specific case.
CREATE FUNCTION ufn_ProperCase(@Text AS VARCHAR(8000))
RETURNS VARCHAR(8000)
AS
BEGIN
-- declare some variables
DECLARE @Reset BIT;
DECLARE @Ret VARCHAR(8000);
...
... AS XML).query('data(/STAFF/GENDER)') AS VARCHAR(10)) AS Gender
FROM
[dbo].[XML_EVENTS]
-- Returns column GENDER for every record/row (eg. "Male")
Or
-- Using .value()
SELECT
CAST(Event_XML ...
... = @GivenRef OR @GivenRef ='')
AND (Forenames LIKE @GivenForenames + '%' OR @GivenForenames = '')
AND (Surname LIKE @GivenSurname OR @GivenSurname = '')
AND (CONVERT(VARCHAR(10),DOB, 103) = @GivenDOB ...
... AS VARCHAR) + ' (new)'
WHEN t1.CHARACTER_MAXIMUM_LENGTH IS NOT NULL AND t2.CHARACTER_MAXIMUM_LENGTH IS NULL
THEN CAST(t1.CHARACTER_MAXIMUM_LENGTH AS VARCHAR) ...
...
MODIFY COLUMN misplaced_column VARCHAR(13) NOT NULL DEFAULT 'DefaultString' COMMENT 'A Comment'
AFTER other_column;
Alternatively
Export the file as a SQL file (data & structure), ...
... (padded with zeros)
How?
So how do we do it? In the above example, Joel Lipman has two qualification records. So let's start with a simple query:
SELECT
RIGHT('000' + CAST(e.ID AS VARCHAR), ...
...
How?
Perhaps we should determine the position of the last needle first (reverse the haystack string and find needle):
DECLARE @Haystack VARCHAR(31);
SET @Haystack = 'String1.String2.String3.String4';
-- ...
... already exists
IF OBJECT_ID ('ufn_DataScramble', 'FN') IS NOT NULL
DROP FUNCTION ufn_DataScramble ;
GO
-- Create user defined function
CREATE FUNCTION ufn_DataScramble
(
@OrigVal varchar(max)
)
RETURNS ...
... 'P') IS NOT NULL
DROP PROCEDURE [usp_CountRecordsPerTablePerColumn];
GO
CREATE PROCEDURE [usp_CountRecordsPerTablePerColumn]
(
@p_Value int,
@p_Column varchar(max)
)
AS
/***********************************************************************************
** ...
... You can put a distinct on it (not forgetting the collate).
This example is expanded in a further article called "Search a database with soundex":
/* USING A CURSOR */
DECLARE @SqlToExecute nvarchar(max);
DECLARE ...
We use cookies to improve your experience on our website. By browsing this website, you agree to our use of cookies. Read more about our Privacy Policy.