A very simple stored procedure in MS SQL Server

Written by Peter Vejrum Terp on . Posted in Peters Blog

Lately I have been working with Stored Procedures, I must admit that it’s not a thing that I previously have had lot of experience in. I thought that it might be the case for other developers out there as well. First very and very short “A stored procedure is a subroutine available to applications that access a relational database system”. If you want to know more about the definition of a Stored Procedure then take a look at Wikipedias definition In this short post, I will try to show how to create a really simple stored procedure.

CREATE PROCEDURE sp_getUser(@userId int) AS
BEGIN
SELECT username, email, userid
FROM [user]
WHERE userid=@userId
END

This is our simple stored procedure, it retrieves user information (username,email,userid) from the table “user”, where the userid is set in the procedure head.

Let’s have a look on how to call the procedure

DECLARE @userId int;
SET @userId = 2;
EXECUTE sp_getUser @userId;

First declare a variable @userId as an int, next set the @userId=2 (we want to retrieve information for the user with id = 2. The next part calss the procedure, where sp_getUser is the procedure we just made, and @userId is the parameter we send to the procedure. The result will be a recordset with username, email and userid for the given user. I hope this very simple example can help getting started with STORED PROCEDURES in MS SQL Server.

How to work better

Written by Peter Vejrum Terp on . Posted in Peters Blog

1. Do one thing at a time
2. Know the problem
3. Learn to listen
4. Learn to ask questions
5. Distinguish sense froem nonsense
6. Accept change as inevitable
7. Admit mistakes
8. Say it simple
9. Be calm
10. Smile

I don’t know who wrote the original text, I just saw it at the office, but there is some truth in the text.

Web fonts using @font-face

Written by Peter Vejrum Terp on . Posted in Peters Blog

When you develope homepages it’s you usually use websafe fonts like Verdana, Arial, Times New Roman and other fonts. That’s fint in most cases, but also a bit boring – you only have a very limited amount of fonts available.

It is of course possible to create images with text, but that’s a “NO GO!”, it’s bad for SEO it’s bad for speed and a lot of other stuff. Therefore normally not a good choice.

The good thing is, there is a solution for that, it’s called @font-face. Using the @font-face, you can get a lot of different fonts using css3 (and some kind of supported in css2). It’s pretty simple and you can actually use a lot of fonts for free (Google has a great library)

Enough talking, time for an example. Examples is often more usefull than 1000 words.

Example
<!DOCTYPE HTML>
<html lang=”da”>
<head>
<meta charset=”utf-8″/>
<link href=”http://fonts.googleapis.com/css?family=Nova+Script” rel=”stylesheet” type=”text/css”/>
<style type=”text/css”>
h1 {font-family: ‘Nova Script’, cursive;}
</style>
<title>@font-face TEST</title>
</head>
<body><h1>Test @font-face with Google Font</h1></body>
<
/html>

Copy the content in italic above and save it as a html file. You will see the magic happen 🙂

Notice
You have to inssure that you are allowed to use the font. A lot of fonts cost money, and it can be hard to find the pricing for use on web.

Great links
Web fonts with @font-face
@font-face generator
Google Web Fonts

Tips for Facebook Updates

Written by Peter Vejrum Terp on . Posted in Peters Blog

Yesterday I got some great tips for Facebook updates, from my good friend Kenneth. You can see the great words below, and a few of my own words 🙂

You will get:
27% better engagement, if the text is 80 characters.
20% better if the message is written outside of the normal working hours.
15% better if the text ends with a question.
10% better on Thursday and Friday in relation to the rest of the week.
10% worse on Saturdays over other days.
3.5% worse from Monday to Wednesday, compared to other days.

Hints
Always post at the same time.
Make personal updates.
Invite to dialogue and conversation
Single call to action increases conversions
Do not post a new update, before the previous update has extinct.
Updates has to give the user value.
Avoid advertising messages.
Know where your fans come from.
Share photos – people like photos.
If you see a spike of unsubscribes, the stop whatever you are doing, and review your content.

Great articles
The Checklist All Facebook Pages Absolutely Must Have
20 Tips For Boosting Facebook Engagement

Danish text: World Wide Energy Net

Written by Peter Vejrum Terp on . Posted in Peters Blog

Jeg hørte i radioen i dag at et af de store issues omkring vedvarende energi, er at få oplagret den overskydende energi. Dette er der sådan set ikke så meget nyt i, og det man i stedet gerne vil gøre er at kunne afsætte (sælge) overskydende energi til andre lande. Dette vil kunne forstærkes ved at skabe en “Energy High Way” igennem Europa, hvor overskydende energi bliver sendt igennem Europa alle retninger, alt efter behov.

Ideen er god, men mener sådan set godt at man kunne udvide tanken ret kraftigt. Hvis man kigger på WWW altså Internettet, så er styrken ved internettet at alle bidrager og at man er meget lidt sårbar pga. de mange forbindelser mellem computere (i grove træk, der er visse sårbarheder).

 Hvis man nu udformede et WWEN (World Wide Enegy Net) hvor man alle både store som små kunne koble sig på et energinet og både købe og sælge strøm. Det kunne være ud fra følgende tanker:

  • Der er en ensartet kobling til alle hjem hvor man kan se det man har forbrugt og det man har produceret af strøm
  • Eva &amp; Bent har måske en solfanger, det samme har Karen og Kurt. De har på sommerdage for meget strøm, som de bibringer nettet med.
  • Mette &amp; Jens har derimod en vindmølle på deres lille gård, de mangler strøm når vinden ikke blæser – så de får brug for strøm fra dem der kan levere det, f.eks. Eva og Bent + Karen og Kurt. Til gengæld vil Mette og Jens have overskydende strøm når der blæser godt.
  • Andre kilder til strøm ville også kunne kobles på nettet. Lige fra store bølge udnyttelses systemer til små opfindelser hjemme i de små hjem.
  • Det er vigtigt at man finder en standardiseret måde at gøre dette på ellers vil det ikke virke optimalt. Standardiseringen skal helst række langt ud over landets grænser.

Tanken er at skabe et stort net hvor alle kan bidrage. Det vil gøre samfundet mindre sårbar og man vil kunne, mindske vores afhængighed af fossile brændstoffer. Landet vil heller ikke i nær så stor grad være afhængige af at skabe store vindmølle parker etc. for at skabe energi nok.

Posts from my blog