Hi,
New to SSMSBoost, and LOVE it. I wish I'd known about it years ago, it could have saved me hundreds of hours!
The script template feature is great and very powerful, but there doesn't appear to be a way to create very useful UPDATE statements from it. What's missing is the ability to build a WHERE clause that targets a primary key column's value. I'd like to build the following with a template:
Code:UPDATE <table name parameter> SET column = value, column = value, ... WHERE <Key column parameter> = <Key column's value>
This would be useful for updating data in one table from another one on a different (remote/unlinked) server. I can do everything except the "[KeyValue]" part, see the template XML below.
I'm not entirely sure how this might be implemented, because you're relying on the value being in the grid somewhere, and you can't always assume it's in the first column.
I think my suggestion would be to: (a) create a new parameter value type which is a dropdown list of column names the user can select, and (b) in the {Rows} definition allow a template to access either that parameter's column name or value for the current row
So in the case of my attached template, when run the user would type the table name and select from a list of columns in the current grid (whether or not that column is in any of the selected regions), and the output would be a list of update statements in the form above.
Caveat: If you script the entire grid as described above this will include the key column (possibly an identity), which will form part of the updates in the SET statement, which is NOT what you want ("UPDATE T SET [Id] = X, ... WHERE [Id] = X"). An additional feature should allow you to exclude columns from the {Columns} enumeration (and, while we're at it, rows from the {Rows} enumeration, say where a column is null?)
Paul
--
Script XML:
Quote:<?xml version="1.0" encoding="utf-16"?> <GridScripterTemplate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Name>UPDATE by Id</Name> <SaveGranularity>Entire</SaveGranularity> <SavePath>C:\Users\phutchison\AppData\Roaming\SSMSBoost\{Year}{Month}{Day}_{Hour}{Minute}{Second}.txt</SavePath> <OpenWithApplication /> <InvokeParametersReplacement>true</InvokeParametersReplacement> <DefaultClipboardFormat>Text</DefaultClipboardFormat> <Document>{Selections}</Document> <Selection>{Rows}</Selection> <SelectionsSeparator>\r\n\r\n</SelectionsSeparator> <Header /> <HeadersSeparator>, </HeadersSeparator> <Row>UPDATE [<Destination tablename, sysname, Enter table name here>] SET {Values} WHERE [<Key column, sysname, Enter key column for update>] = [X] </Row> <RowsSeparator>\r\n</RowsSeparator> <ColumnName>[{ColumnName}]</ColumnName> <ColumnNamesSeparator>, </ColumnNamesSeparator> <Value>[{ColumnName}] = {Value}</Value> <ValuesSeparator>, </ValuesSeparator> <StringFormatter> <Pattern>'{Value}'</Pattern> </StringFormatter> <NStringFormatter> <Pattern>N'{Value}'</Pattern> </NStringFormatter> <IntegerFormatter> <Pattern>{Value}</Pattern> <Format>D</Format> </IntegerFormatter> <DoubleFormatter> <Pattern>{Value}</Pattern> <Format>G</Format> </DoubleFormatter> <CurrencyFormatter> <Pattern>CAST({Value} as MONEY)</Pattern> <Format>G</Format> </CurrencyFormatter> <DateTimeFormatter> <Pattern>CAST('{Value}' as DATETIME)</Pattern> <Format>yyyyMMdd HH:mm:ss.fff</Format> </DateTimeFormatter> <DateFormatter> <Pattern>CAST('{Value}' as DATE)</Pattern> <Format>yyyyMMdd</Format> </DateFormatter> <TimeFormatter> <Pattern>CAST('{Value}' as TIME)</Pattern> <Format>HH:mm:ss.fff</Format> </TimeFormatter> <BooleanFormatter> <Pattern>{Value}</Pattern> <TrueString>1</TrueString> <FalseString>0</FalseString> </BooleanFormatter> <GuidFormatter> <Pattern>CAST ('{Value}' as uniqueidentifier)</Pattern> <Format /> </GuidFormatter> <BinaryFormatter> <Pattern>{Value}</Pattern> </BinaryFormatter> <XmlFormatter> <Pattern>{Value}</Pattern> </XmlFormatter> <SpatialFormatter> <Pattern>'{Value}'</Pattern> <AsText>true</AsText> </SpatialFormatter> <NullString>NULL</NullString> <UseInvariantCulture>true</UseInvariantCulture> <MaxCharsPerValue>0</MaxCharsPerValue> <ValuesEncodeMethod>SqlEncode</ValuesEncodeMethod> </GridScripterTemplate>
|