March 10, 2023 at 7:47 pm
If ChatGPT set that up and it was quick and easy that's amazing. Before it writes queries it would be nice if it did boring and boilerplate work
There is a new skill you can acquire called "Prompt Engineering" which apparently (according to some YouTube videos) attracts very high salaries - lol (I don't think so). It's basically how you ask ChatGPT questions in a way to get better answers. I just added "Please create a test table (#temp) with column Col1 and some test data and the query I need to solve it" to the end of the OP's question and pasted it into ChatGPT:
The query it produced was actually the simplest one yet:
SELECT
LEFT(Col1, CHARINDEX(' ', Col1 + ' ', CHARINDEX(' ', Col1) + 1) - 1) AS FirstTwoWords
FROM
#temp
March 10, 2023 at 7:57 pm
Awesome test rig, Jonathan!
Here's another method that I think you'll appreciate performance wise. (didn't see the post above when I posted).
SET STATISTICS TIME,IO OFF;
DROP TABLE IF EXISTS #4;
PRINT 'Start ***************************************************** "Lost Wax Method"';
SET STATISTICS TIME,IO ON;
SELECT first2_in_order = RTRIM(LEFT(t.Col1,ISNULL(NULLIF(CHARINDEX(' ',t.Col1,CHARINDEX(' ',t.Col1)+1),0),8000)))
INTO #4
FROM #temp t;
SET STATISTICS TIME,IO OFF;
--Jeff Moden
Change is inevitable... Change for the better is not.
March 10, 2023 at 8:48 pm
The only problem that the ChatGPT version has is when the first "word" is 8000 characters long or the combination of the first and second words is 8000 characters long. Then you'll get the dreaded error of ...
Msg 537, Level 16, State 2, Line 86
Invalid length parameter passed to the LEFT or SUBSTRING function.
While that's "Not likely", I hate finding out when it does occur by accident.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 10, 2023 at 9:43 pm
It's basically how you ask ChatGPT questions in a way to get better answers.
That means that all of those people are doomed. 😀 Stop and think about the questions they ask here and on other forums. No effort on the part of many. They're doomed. 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
March 10, 2023 at 10:40 pm
If their plan fails, they can always go back to tipping Dogecoin or peddling courses on how to get rich quick by buying cheap stuff on AliBaba and reselling it on Fulfilled by Amazon
March 11, 2023 at 5:15 am
If their plan fails, they can always go back to tipping Dogecoin or peddling courses on how to get rich quick by buying cheap stuff on AliBaba and reselling it on Fulfilled by Amazon
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 16 through 20 (of 20 total)
You must be logged in to reply to this topic. Login to reply