Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 The Yak Corral
 Noob Joy!

Author  Topic 

Ledell
SQL NASCAR Parsing Chick

107 Posts

Posted - 2012-08-13 : 20:18:48
After stepping away from SQL Server for a few years [and not really being all that advanced with it in the first place] ... just wanted to share my noobish excitement at creating my first User Defined Function.

The articles on this site are some of the best I've come across on the interwebs. Really looking forward to diving back into the world of SQL Server again!



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Got some code from Rob. Can anyone help?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-14 : 07:16:24
Welcome (back) to the world of SQL Server !!

My noobish excitement was when I figured out that I can update more than one row with a single update statement. In my excitement, I stood up at my desk and did a hoola twist ( http://www.youtube.com/watch?v=6zBGR1yNOWo )

I won't tell you how I was updating until I made that great discovery.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-08-14 : 08:24:08
quote:
Originally posted by sunitabeck

I won't tell you how I was updating until I made that great discovery.



Let me guess:

DECLARE foo CURSOR FOR
SELECT [key] FROM <TheTable>

OPEN foo

FETCH NEXT FROM foo INTO @key
WHILE ( @@FETCH_STATUS = 0 ) BEGIN
UPDATE <theTable> SET [a] = 'b' WHERE [key] = @key
FETCH NEXT FROM foo INTO @key
END
CLOSE foo
DEALLOCATE foo


I certainly did **** like that back in the early days...... I'm sure most of us probably did...

well, maybe not peso -- He may have been born ready to write set based code.

Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-14 : 09:14:09
quote:

Let me guess:[code]
DECLARE foo CURSOR FOR
SELECT [key] FROM <TheTable>


No! That was too complicated for me! I wrote wrote a little C# program to generate all the update statements that I wanted, one for each row, copied and pasted into SSMS and voila!!
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-08-14 : 09:37:26
Did you ever use Excel to generate SQL statements? I used to do that A LOT, and I still do every now and then.

And it's not just me: http://thesqlagentman.com/2012/08/cheating-on-sql-with-excel/
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-08-14 : 11:20:57
quote:
Originally posted by Transact Charlie


well, maybe not peso -- He may have been born ready to write set based code.

Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/



Peso was not born.

bcp "SELECT Peso FROM Mom.Womb.Kid" queryout Kid.Peso.dat











How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2012-08-14 : 15:49:15
quote:
Originally posted by robvolk

Did you ever use Excel to generate SQL statements? I used to do that A LOT, and I still do every now and then.

And it's not just me: http://thesqlagentman.com/2012/08/cheating-on-sql-with-excel/



I still use Excel to generate SQL statements.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-14 : 17:01:05
quote:
Originally posted by robvolk

Did you ever use Excel to generate SQL statements? I used to do that A LOT, and I still do every now and then.

And it's not just me: http://thesqlagentman.com/2012/08/cheating-on-sql-with-excel/



I always still use them to generate INSERT scripts from set of sample ad-hoc data

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-08-14 : 21:29:41
I don't know whether it's a comment on my perverted mind, or on society's obsession, but every time I see this thread I think the title is "Boob Job".
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-08-14 : 21:39:27
quote:
Originally posted by robvolk

I don't know whether it's a comment on my perverted mind, or on society's obsession, but every time I see this thread I think the title is "Boob Job".



Me too. But i did not misread the 2nd word. This, i tribute it to my farsighted vision


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2012-08-15 : 09:17:23
quote:
Originally posted by khtan

quote:
Originally posted by robvolk

I don't know whether it's a comment on my perverted mind, or on society's obsession, but every time I see this thread I think the title is "Boob Job".



Me too. But i did not misread the 2nd word. This, i tribute it to my farsighted vision


KH
[spoiler]Time is always against us[/spoiler]





Personally I attest it to my dirty mind

Jim
Users <> Logic
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-08-16 : 06:25:04
quote:
Originally posted by robvolk

Did you ever use Excel to generate SQL statements? I used to do that A LOT, and I still do every now and then.

And it's not just me: http://thesqlagentman.com/2012/08/cheating-on-sql-with-excel/


I had used it several times in the past. Very handy particulary when you want to import EXCEL data to non-MS RDBMS

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-08-16 : 06:29:13
Haven't had to do this at all in my current position but in my previous job, I wrote a simple program to turn a csv file into a sql script of inserts.

It made a temp table with column names taken from the header row and then batches of 50 insert statements at a time...

ah the good ol' days when I had no clue at all what I was doing most of the time.

Transact Charlie
Msg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
http://nosqlsolution.blogspot.co.uk/
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-16 : 07:47:00
I use Regular Expressions on TextPad (http://www.textpad.com/) to generate almost all of my insert statements and sample data.

I am not an expert on regular expressions, but with just the little that I know, I am able to do pretty much anything much faster than I could in Excel.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-08-16 : 09:40:27
I've got a lightning talk on using Regular Expressions in SSMS that includes one to reformat tab-separated data pasted from Excel into INSERT statements. The only problem is that Microsoft changed some of the regex from the Perl standard and it's very annoying to deal with.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-16 : 09:55:47
If you have the time to read it, the best book on regular expressions that I have seen is "Mastering Regular Expressions" by Jeffrey Friedl. He tells it masterfully like a story teller, and it is a pleasure to read. He covers various dialects of it, the rationale for the way something is done and dives deep to give you a thorough understanding. I have ready only the first chapter or two, but one of these days I am going to read it from cover to cover! http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124/
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2012-08-29 : 04:42:52
Is it just me that finds this thread just a little scary?

-----------

Insanity: doing the same thing over and over again and expecting different results.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2012-08-29 : 09:26:10
quote:
Originally posted by visakh16

quote:
Originally posted by robvolk

Did you ever use Excel to generate SQL statements? I used to do that A LOT, and I still do every now and then.

And it's not just me: http://thesqlagentman.com/2012/08/cheating-on-sql-with-excel/



I always still use them to generate INSERT scripts from set of sample ad-hoc data

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/






I just did this yesterday to load 4000 rows into a table from an Excel worksheet.





CODO ERGO SUM
Go to Top of Page
   

- Advertisement -